Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Any Examples on how to send via email a reply to my HTML form:

by villa (Initiate)
on Dec 12, 2001 at 22:57 UTC ( [id://131343]=perlquestion: print w/replies, xml ) Need Help??

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

Hello Perl Monks, Do's anyone have any examples as to how to send a email reply back to my HTML if someone selects the my email value;ie ($form_name, $email) = split (/=/, $fields[1]) on my + HTML form and if not to send a Thankyou. Best Rgds;
#!/usr/bin/perl -w # Get the submitted data $content_length = $ENV{'CONTENT_LENGTH'}; # Read user data into script variables read (STDIN, $form_data, $content_length); $form_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C",hex ($1))/eg; # Replace "+" sign with " "space char. $form_data =~ s/\+/ /g; # Split $form_data into name/value pairs: @fields = split (/&/, $form_data); # Init variables with form data values from following fields: ($form_name, $name) = split (/=/, $fields[0]); ($form_name, $email) = split (/=/, $fields[1]); ($form_name, $comments) = split (/=/, $fields[2]); # Send back user confirmation: print << "END_OF_REPLY"; Content-type: text/html <HTML> <HEAD> <TITLE>THANKYOU!! if no email entered </TITLE> </HEAD> <BR><BR><BR> <H1 ALIGN=CENTER>Thankyou $name !</H1> <BR> <BR> <H1 ALIGN=CENTER>See you next time!!</H1> <BR> <BR> </HTML>
END_OF_REPLY

Replies are listed 'Best First'.
Re: Any Examples on how to send via email a reply to my HTML form:
by kwoff (Friar) on Dec 12, 2001 at 23:32 UTC
    First of all, use CGI.pm (or Apache::Request) rather than parsing form data yourself.

    Anyway, have separate names for the different operations (one operation is "send email", the other is "don't send email"). Maybe they are the names for submit buttons. Then, you check which name is present in the form data.

    if ($form_name eq 'send email') { show_send_email_page(); } else { show_no_email_page(); }
Re: Any Examples on how to send via email a reply to my HTML form:
by Gerard (Pilgrim) on Dec 12, 2001 at 23:35 UTC
    If you are using unix you could use sendmail, which is a very common unix program.
    $mail_prog = "/usr/sbin/sendmail"; if ($email eq "no") { #Do your html stuff } else { &SendMail($reciptent, $sender); } sub SendMail { my ($recipient,$sender) = @_; open(MAIL, "|$mail_prog -t") || &error("Could not send out emails" ); print MAIL "To: $recipient \n"; print MAIL "From: $sender <$sender>\n"; print MAIL "Subject: database entry\n"; print MAIL "added\n\n"; print MAIL"------------------------------------------------------- +----------------------------------\n"; print MAIL ""; print MAIL "\n\n"; print MAIL "\n\n"; close (MAIL); } # end SendMail function
    Note: I borrowed most of code from this node, and I haven't tested. I hope that this is what you are after.
    Regards,
    Gerard
    Update: Hmmmm, It seems that I may have completely misread the question. Oh well, I haven't slept in over forty hours, so I suppose I can be excused : )

      Regarding the e-mail portion of your question, I did something that looks a lot like Gerard's above (we must have the same collection of books), but I used the Mail perl module:

         use Mail::Mailer;

      My code that relates to the e-mailing is as follows:

      $mailer = Mail::Mailer->new("mail"); $mailer->open({From=>$from_address, To=>$to_address, Subject=>$subject, }) or die "Can't open: $!\n"; print $mailer @body; $mailer->close();

      Of course, the string variables are all set in code lines above this excerpt.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-04-25 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found