#!/usr/bin/perl # mail_form.cgi # bundle up form output and mail it to the specified address use strict; use warnings; # configuration: my $sendmail = '/usr/sbin/sendmail'; # where is sendmail? my $recipient = 'spython01@gmail.com'; # who gets the form data? my $sender = 'forms@perlcgi.tk'; # default sender? my $site_name = 'PerlCGI'; # name of site to return to after my $site_url = '/'; # URL to return to after # script proper begins... use CGI qw(:standard); # bundle up form submissions into a mail_body my $mail_body = ''; foreach my $field (param) { foreach my $value (param($field)) { $mail_body .= "$field: $value\n"; } } # set an appropriate From: address my $email = ''; if ($email = param('email')) { # the user supplied an email address $email =~ s/\n/ /g; $sender = $email; } # send the email message open MAIL, "|$sendmail" or die "Can't open pipe to $sendmail: $!\n"; print MAIL <<"EOF"; To: $recipient From: $sender Subject: Sample Web Form Submission $mail_body EOF close MAIL or die "Can't close pipe to $sendmail: $!\n"; # now show the thank-you screen print header, <<"EOF"; Thank you

Thank you

Thank you for your form submission. You will be hearing from me shortly.

Return to $site_name.

EOF