#!/usr/local/bin/perl -w # sendemail.pl # Gets information from the web form and send's email as specified # Field names currently known: # Subject - subject text string # To - email address of who it is going to # Name - name of person completing the form # Email - Return email address # Message - message to be sent # SendToURL - URL for user to click on after email is sent. $version="V1.03/September 23, 2011"; # September 23, 2011. Fix code to remove ">" from temporary filename # so it can be removed after it is used. rcg # May 24, 2000 V1.04. Fix code that handles next to last entry. Add # more tests for punctuation and other "special" characters. # May 19, 2000 V1.03. Add code to check for no more & in string in order # to terminate. # March 30, 2000 V1.02 Add mapping of %22 to double quote # March 24, 2000 V1.01 Change %3F's to "?". # March 22, 2000 V1.00 Original version # R. Groman $|=1; $last_flag="no"; print STDOUT ("Content-type: text/html\n\n", "\n
\n");
$string = \n");
while ($string) {
$string =~ s/^(.*)&(.*)/$1/;
# print STDOUT ("string=$string \n");
# Check for last entry. Doesn't seem to work as before 5/19/00
last if $last_flag eq "yes";
unless ($string =~ m/&/ ) {
$substring = $string;
undef $string;
$last_flag="yes";
goto LOOP;
}
last unless defined $string;
}
#Check for valid message
unless (exists $param{'Name'} and defined $param{'Name'} and
$param{'Name'} =~ m/\w+/ ) {
print STDOUT ('
\n");
$substring = $2;
unless (defined $substring) {
if (defined $string) {
$substring = $string;
undef $string;
}
else { last; }
}
LOOP:
# print STDOUT ("substring=$substring
\n");
($key, $value) = split /=/, $substring;
$key =~ s/\+/ /g;
$key =~ s/\%40/@/g;
$value =~ s/\+/ /g;
$value =~ s/\%40/@/g;
$value =~ s/\%0D\%0A/\n/g;
$value =~ s/\%3F/\?/g;
$value =~ s/\%22/\"/g;
$value =~ s/\%09/\t/g;
$value =~ s/\%27/\'/g;
$value =~ s/\%2F/\//g;
$value =~ s/\%2C/\,/g;
$value =~ s/\%2E/\./g;
$value =~ s/\%28/\(/g;
$value =~ s/\%29/\)/g;
$value =~ s/\%2A/\*/g;
$value =~ s/\%2B/\+/g;
$value =~ s/\%2D/\-/g;
$value =~ s/\%21/\!/g;
$value =~ s/\%23/\#/g;
$value =~ s/\%24/\$/g;
$value =~ s/\%25/\%/g;
$value =~ s/\%26/\&/g;
$param{$key} = $value;
# print STDOUT ("key=$key, value=$valueYou did not include a reasonable name',
" entry. ",
" Please click ",
"your browser\'s \"Back\" button, enter your name, ",
'and resubmit. Thank you.
',"\n");
exit;
}
unless (exists $param{'Email'} and defined $param{'Email'} and
$param{'Email'} =~ m/\@/ ) {
print STDOUT ('You did not include a reasonable return',
" e-mail address. ",
" Please click ",
"your browser\'s \"Back\" button, correct the address, ",
'and resubmit. Thank you.
',"\n");
exit;
}
unless (exists $param{'Message'} and defined $param{'Message'} and
$param{'Message'} =~ m/\w+/) {
print STDOUT ('You did not include a message to send. ',
"Please click your browser\'s \"Back\" button, ",
"correct the message, and resubmit. Thank you.",
'
',"\n");
exit;
}
&mailmessage;
if (exists $param{'SendToURL'} and defined $param{'SendToURL'} ) {
$param{'SendToURL'} =~ s/\%3A/\:/g;
$param{'SendToURL'} =~ s/\%2F/\//g;
$param{'SendToURL'} =~ s/\%7B/\{/g;
$param{'SendToURL'} =~ s/\%7D/\}/g;
$param{'SendToURL'} =~ s/\%3D/\=/g;
$param{'SendToURL'} =~ s/\%2C/\,/g;
print STDOUT ('Thank you for sending your message. To access ',
'the data, ',
'click here',
'
');
}
else {
print STDOUT ('Thank you for sending your message. ',
"Please click your browser\'s \"Back\" button, ",
"to continue. Thank you.",
'
',"\n");
}
print STDOUT ("
Version: ",$version, "\n\n");
exit 0;
#---------------------------------------------------------------------------
sub mailmessage {
#Send a message to the user.
#The message sent will be in the strings $_[1] and $_[2]
#The prefix string is in $_[0]
my ( $mailfile, $message0, $message1, $prefix, $who);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
$prefix=$_[0];
$message0=$_[1];
$message1=$_[2];
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
if ( $year < 1000 ) {$year = $year + 1900; }
$mon++;
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; }
$mailfile="/tmp/sendmess" . $year . $yday . $hour . $min . $sec . ".tmp";
if ( open TEMPFILE, "> $mailfile") {
if ( exists $ENV{'REMOTE_HOST'} ) {$who=$ENV{'REMOTE_HOST'} ; }
elsif (exists $ENV{'REMOTE_ADDR'} ) {$who=$ENV{'REMOTE_ADDR'} ; }
else {$who="not available"; }
print TEMPFILE ("Message from web\n");
print TEMPFILE (" Date of message: $year/$mon/$mday $hour:$min\n");
print TEMPFILE (" From: $param{'Name'}\n");
print TEMPFILE (" From host: $who\n");
print TEMPFILE (" Email address: $param{'Email'}\n");
print TEMPFILE (" Subject: $param{'Subject'}\n");
print TEMPFILE (" Message text:\n$param{'Message'}\n");
close TEMPFILE;
# `/usr/bin/mail -w dmo\@globec.whoi.edu <$mailfile`;
$param{'To'} =~ s/\@/\\\@/;
`/usr/bin/mail -w $param{'To'} <$mailfile`;
unlink $mailfile;
}
return;
}