Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

send form results by email

by Anonymous Monk
on Mar 12, 2003 at 15:55 UTC ( [id://242397]=perlquestion: print w/replies, xml ) Need Help??

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

I have a cgi script written in perl. I have a subroutine which prints out the results from my form data. 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; But, this has no effect. Any suggestions...

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

    according to perldoc -f filehandle you can pass the filehandle to the subroutine

    open my $sendmail, "|/path/to/sendmail -t $to" or die("couldn't open p +ipe to sendmail"); print_details($sendmail);

    BTW: you don't have to use the & to call a subroutine, and, IMVHO, should be aware of it's meaning before doing so.

    regards,
    tomte


      Thanks Tomte, I tried your way...but it does not work. I have posted the same question again along with a piece of my code. May be u can check it and then give me a suitable suggestion. I would appreciate if u do so.

      edited: Wed Mar 12 16:42:02 2003 by jeffa - i moved your code to this thread, the id is still the same 242417

send form results by email
by Anonymous Monk on Mar 12, 2003 at 16:34 UTC
    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...

      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...
      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


Re: send form results by email
by ibanix (Hermit) on Mar 12, 2003 at 16:35 UTC
    Any suggestions...

    Post your code.

    Cheers,
    ibanix

    $ echo '$0 & $0 &' > foo; chmod a+x foo; foo;
Re: send form results by email
by PriNet (Monk) on Mar 12, 2003 at 20:30 UTC
    i have a quick cut and dry email subroutine for a "module" that i define in the top then just "call" it when i wish to send myself email.... i.e.; sendemail($server,$bounchaddess,$@to,$@from,$sender,$recipient,$subject,$body) ... have you tried to create a "subroutine module" for these kinds of calls?

    you mean there's any easier way?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found