paav1 has asked for the wisdom of the Perl Monks concerning the following question:

How do I create a form that would email the information to someone that the user would have specified, without detecting the user's email address. Example if I am the user and I want to send this form to user X, who will email that with his/her email address to user Y. I am supposed to write a script for work, that users can fill out a form, send that to their managers, who would email that to the appropriate department. I tried finding help on the web, however I kept finding information that emails to one specific user and not to anyone that the user specifies. Thanks Paav1
  • Comment on how do i send an email to someone specified by the user?

Replies are listed 'Best First'.
Re: how do i send an email to someone specified by the user?
by kilinrax (Deacon) on Nov 15, 2000 at 21:36 UTC
    Though I can't be sure (You're question was a bit garbled), it sounds to me you want something like this:
    #!/usr/bin/perl -wT eval 'exec perl -wT -S $0 ${1+"$@"}' if 0; # not running under some shell require 5; use strict; use CGI; use URI::URL; use Mail::Mailer; use vars qw( @errors ); my $subject = "Automated Message From $0"; my $mailtext; my $forwardurl = '/thankyou.html'; my $query = new CGI; my @params = $query->param; my $email = $query->param('email'); my $mailto = $query->param('mailto'); # check email address is valid checkemail($email) if $email; # construct the message for whoever's being sent the form my $param; my $value; my @values; foreach $param(@params) { @values = $query->param($param); if ($query->param('other_'.$param)) { foreach $value (@values) { if ($value eq 'other') { push (@values, $query->param('other_'.$param)); last; } } } @values = grep { $_ ne 'other' } @values; ($value = join(', ', @values)) && ($mailtext .= "\u\L$param\E: $valu +e\n"); } if (@errors) { $mailtext .= 'IMPORTANT! The following error'. (@errors>1 ? 's were' + : ' was') ." encountered during execution:\n". join("\n",@errors). " +\n\n"; } sendmail($email, $mailto, $subject, $mailtext); # send off the mail print "Location: $forwardurl\n\n"; # forward the user to + a 'thank you' page exit; sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new('sendmail'); }; if ($@) { push (@errors, "Couldn't send mail: $@"); return 0; } else { $mailer->open({ From => $from, To => $to, Subject => $subject }); print $mailer $body; if (close ($mailer)) { return 1; } else { push (@errors, "Couldn't close mailer: $!"); return 0; } } } sub checkemail{ my $addr = shift; my $validmail; return 0 unless eval { unless ($validmail = Email::Valid->address( -address => $addr, -mxcheck => 1 )) { push (@errors, "address failed $Email::Valid::Details check."); if ($Email::Valid::Details eq 'rfc822') { push (@errors, "$addr is unlikely to be a valid email address" +); } elsif ($Email::Valid::Details eq 'mx') { (my $domain = $addr) =~ s/^[^\@]+\@//; push (@errors, "$domain does not seem to have a mailserver"); } return 0; } }; if ($@) { push (@errors, "An error was encountered: $@"); return 0; } return 1; }
    This script will mail all the data in the form to the address given in the form field 'mailto'. If you want the address mailed to to be fixed, simply set $mailto to that address.
    Hope this helps ;-)
Re: how do i send an email to someone specified by the user?
by merlyn (Sage) on Nov 15, 2000 at 21:38 UTC
    Be careful how you do this, or it'll be used as a spam relay.
Re: how do i send an email to someone specified by the user?
by kilinrax (Deacon) on Nov 15, 2000 at 21:13 UTC
Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Oct 03, 2003 at 13:00 UTC
    well i don't really care what ever i just want to send an email to my dad thats all im asking nothing else i already know how to do it i just need to know where to go for it that all thankyou have a nice day

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Jan 22, 2004 at 18:39 UTC
    MAIL TO MS.TANYA TAYLOR AT VENTURI STAFFING PARTNERS HI TANYA IF YOU GET THIS EMAIL PLEASE CALL ME AT 773-424-8329 SEND TO tdtaylor@venturipartners.com SIGN BARBARA CANNADY

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Jan 22, 2003 at 02:24 UTC
    how do i send and email to a boy

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Dec 26, 2003 at 18:50 UTC
    Amanda Jung Quiz #5 Period 5 1. She used a compact mirror. 2. Pretty sure the dog died. 3. That whenever the Nurse decides he can leave than he can go. He has no say so. 4.? 5.Because McMurphy knows better and Fredrickson and Seafelt don't. 6. Because he thinks that whatever he does isn't good enough for anyone else. 7. He starts having nightmares of Harding's wife. 8. They are talking about the ECT and that it sounds bad, but it's good for the patients. 9. Because he is committed and they can get out whenever they want to they just choose not to. 10. Putting his hand through the window to get cigarettes.

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Jan 13, 2004 at 22:11 UTC
    how do i send an email to anyone

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Oct 29, 2003 at 01:13 UTC

    Re: how do i send an email to someone specified by the user?

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Dec 07, 2003 at 06:43 UTC
    how do i write an send a email to people. using my yahoo address? please email me. looking4happiness@webtv.net

    Originally posted as a Categorized Answer.

Re: how do i send an email to someone specified by the user?
by Anonymous Monk on Dec 26, 2003 at 18:51 UTC
    Amanda Jung Quiz #5 Period 1 1. She used a compact mirror. 2. Pretty sure the dog died. 3. That whenever the Nurse decides he can leave than he can go. He has no say so. 4.? 5.Because McMurphy knows better and Fredrickson and Seafelt don't. 6. Because he thinks that whatever he does isn't good enough for anyone else. 7. He starts having nightmares of Harding's wife. 8. They are talking about the ECT and that it sounds bad, but it's good for the patients. 9. Because he is committed and they can get out whenever they want to they just choose not to. 10. Putting his hand through the window to get cigarettes.

    Originally posted as a Categorized Answer.