#!/usr/local/bin/perl
# MailForm.pl - Email form data
# Substiture your own values here!
$MailCmd = "/usr/lib/sendmail -t"; # Your email program command
$ToAddr = "tracy\@bydisn.com"; # Your email address
$FromAddr = "tracy\@bydisn.com"; # From email address
$Subject = "Test MailForm.pl"; # Email subject
$ResultsPage = "[URL unfurl="true"]http://www.bydisn.com/Results.html";[/URL] # Page to redirect to when done
# End user values
# Flush stdout
$| = 1;
# Get the form data
if ( $ENV{"REQUEST_METHOD"} eq "GET" ) {
$FormData = $ENV{"QUERY_STRING"};
} elsif ( $ENV{"REQUEST_METHOD"} eq "POST" ) {
read(STDIN, $FormData, $ENV{"CONTENT_LENGTH"});
} else {
print "Content-type: text/html\n\n";
print qq[<html><head></head><body><h2>Invalid Form Method: $ENV{"REQUEST_METHOD"}</h2></body></html>];
}
# Split data into list (array) of key=value entries
@FormData = split(/&/, $FormData);
# Process the FormData list
foreach $x (0 .. $#FormData) {
# Convert plus signs back to spaces
$FormData[$x] =~ s/\+/ /g;
# Split into key and value (on the first equal sign found).
($key, $val) = split(/=/, $FormData[$x], 2);
# Convert %XX sequences into characters
$key =~ s/%(..)/pack("c", hex($1))/ge;
$val =~ s/%(..)/pack("c", hex($1))/ge;
# Replace list element with converted values
$FormData[$x] = $key . "=" . $val;
# Create associative array member
# Null value ('\0') separates multiple values
$FormData{$key} .= "\0" if (defined($FormData{$key}));
$FormData{$key} .= $val;
}
# Open email pipe
open(MAIL, "| ".$MailCmd);
# Print headers
print MAIL "To: $ToAddr\n";
print MAIL "From: $FromAddr\n";
print MAIL "Subject: $Subject\n";
print MAIL "\n";
# Print form variables
foreach my $key (keys %FormData) {
print MAIL "$key: $FormData{$key}\n";
}
# Close email pipe
close(MAIL);
# Redirect to results page
print "Location: $ResultsPage\n\n";
exit 0;
1;