[thelist] Perl mailto and redirect
Anthony Baratta
Anthony at Baratta.com
Mon Jan 15 12:42:31 CST 2001
Here is a cheap and dirty form mailer in perl. You'll need cgi-lib.pl which
you can get here (put it in the same directory as the script):
http://cgi-lib.berkeley.edu/
If should be relatively self explanatory. Since the script "sorts" the form
inputs, you can pre-ordain the order by naming your form elements with a
"#_", e.g. 1_Name, 2_Address, 3_City, 4_State, etc.
#!/usr/bin/perl
###################
## contact.cgi
##
##
###################
###################
## Extra INC Paths
##
#BEGIN {unshift @INC, './cgi-bin' };
###################
## Required Libraries
##
require "cgi-lib.pl";
###################
## User Setup Parameters
##
$varSendMail = "/usr/sbin/sendmail -t -n";
$SendAs = "Mail\@Mail.com";
$EmailResultsTo = "Mail\@Mail.com";
$BCCEmailResultsTo = "Mail\@Mail.com";
$EmailSubject = "Email Subject Here";
$RedirectTo = "http://www.foo.com"
###################
## Parsing Data
##
$varRetForm = &ReadParse(\%input);
###################
## Begin Program
##
if ($varRetForm) {&MailReceipt;}
print "Location: $RedirectTo\n\n";
exit;
##
## MailReceipt
##
sub MailReceipt {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon++;
$year = $year + 1900;
if ($mon < 10) {$mon = "0" . $mon;}
if ($mday < 10) {$mday = "0" . $mday;}
if ($hour < 10) {$hour = "0" . $hour;}
if ($min < 10) {$min = "0" . $min;}
if ($sec < 10) {$sec = "0" . $sec;}
$varEmailBody = "Request Date: $mon\-$mday\-$year $hour\:$min:$sec\n\n";
foreach $var(sort keys %input) {
$varEmailBody .= "$var: $input{$var}\n";
} # end
$varEmailBody .= "\n\n-------End of Email--------\n\n";
open (MAIL, "| $varSendMail") || print "cannot open mail program";
print MAIL "To: $EmailResultsTo \n";
print MAIL "From: $SendAs \n";
if ($BCCEmailResultsTo ne "") {
print MAIL "bcc: $BCCEmailResultsTo \n";
}
print MAIL "Subject: \n\n";
print MAIL "$varEmailBody\n";
print MAIL "\n\n";
close(MAIL) || print "mail pipe exited $?";
} # end sub MailReceipt
More information about the thelist
mailing list