cgi-dev

Repository that serves as my CGI "scratchpad" to try things out.
git clone git://git.samirparikh.com/cgi-dev
Log | Files | Refs | README

mail_form.cgi (1406B) - raw


      1 #!/usr/bin/perl
      2 
      3 # mail_form.cgi
      4 
      5 # bundle up form output and mail it to the specified address
      6 
      7 use strict;
      8 use warnings;
      9 
     10 # configuration:
     11 
     12 my $sendmail  = '/usr/sbin/sendmail'; # where is sendmail?
     13 my $recipient = 'spython01@gmail.com';  # who gets the form data?
     14 my $sender    = 'forms@perlcgi.tk';  # default sender?
     15 my $site_name = 'PerlCGI';            # name of site to return to after
     16 my $site_url  = '/';          # URL to return to after
     17 
     18 # script proper begins...
     19 
     20 use CGI qw(:standard);
     21 
     22 # bundle up form submissions into a mail_body
     23 
     24 my $mail_body = '';
     25 
     26 foreach my $field (param) {
     27     foreach my $value (param($field)) {
     28         $mail_body .= "$field: $value\n";
     29     }
     30 }
     31 
     32 # set an appropriate From: address
     33 my $email = '';
     34 if ($email = param('email')) {
     35     # the user supplied an email address
     36     $email  =~ s/\n/ /g;
     37     $sender = $email;
     38 }
     39 
     40 # send the email message
     41 
     42 open MAIL, "|$sendmail" or die "Can't open pipe to $sendmail: $!\n";
     43 
     44 print MAIL <<"EOF";
     45 To: $recipient
     46 From: $sender
     47 Subject: Sample Web Form Submission
     48 
     49 $mail_body
     50 EOF
     51 
     52 close MAIL or die "Can't close pipe to $sendmail: $!\n";
     53 
     54 # now show the thank-you screen
     55 
     56 print header, <<"EOF";
     57 <HTML>
     58 <HEAD>
     59 <TITLE>Thank you</TITLE>
     60 </HEAD>
     61 
     62 <BODY>
     63 
     64 <H1>Thank you</H1>
     65 
     66 <P>Thank you for your form submission. You will be hearing 
     67 from me shortly.</P>
     68 
     69 <P>Return to 
     70 <A HREF="$site_url">$site_name</A>.</P>
     71 
     72 </BODY>
     73 </HTML>
     74 EOF
     75