Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

send form results by email

by Anonymous Monk
on Mar 12, 2003 at 16:34 UTC ( [id://242417]=note: print w/replies, xml ) Need Help??


in reply to send form results by email

I have a cgi script written in perl. I have a subroutine which prints out the results from my form data
sub print_details{ print "\nWe have recieved your order for a $pizza_size pizza with "; &pizza_toppings; }

Since I want the same results to appear when I send an email, how do I call the subroutine? I tried print SENDMAIL &print_details; as the code below. But, this has no effect.
# send e-mail my $sendmail; $sendmail="/usr/sbin/sendmail -t"; open(SENDMAIL , "| $sendmail") ||die("unable to open"); print SENDMAIL "From: $txt_email\n"; print SENDMAIL "To: abc123@hotmail.com\n"; print SENDMAIL "Reply-To: abc123@hotmail.com \n"; print SENDMAIL "Subject: YOUR PIZZA ORDER\n" ; print SENDMAIL &print_details; close (SENDMAIL);
Any suggestions...

Replies are listed 'Best First'.
Re: send form results by email
by jasonk (Parson) on Mar 12, 2003 at 16:40 UTC

    Since you didn't escape the @ in your email addresses (and since you didn't use -w which would have told you this), the string @hotmail is being seen as an array, so your email is getting sent out with these headers:

    From: somebody@somewhere.com
    To: abc123.com
    Reply-To abc123.com
    Subject: YOUR PIZZA ORDER
    

    We're not surrounded, we're in a target-rich environment!
      Thanks jasonk, I corrected those two lines with
      print SENDMAIL "To: abc123\@hotmail.com\n"; print SENDMAIL "Reply-To: abc123\@hotmail.com \n";
      Even with those changes, it does not work...
Re: send form results by email
by Tomte (Priest) on Mar 12, 2003 at 16:52 UTC
    Well, something like this should do the trick:

    sub print_details { my $fh = shift; print $fh "We have recieved your order for a $pizza_size pizza with +"; pizza_toppings(); } open my $sendmail, "| /usr/sbin/sendmail -t" or die ("no sendmail??"); [...] print $sendmail "Subject: ...\n\n"; print_details($sendmail); close $sendmail;

    Just make sure you call print_details everywhere with a filehandle as argument.
    If this doesn't help you, read the docs I pointed you to, it's all there. ( and here too: open, perlfaq filehandle )

    regards,
    tomte


Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://242417]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found