#!/usr/bin/perl
#
# MAILER.CGI
# by Matt Kruse (mkruse@saunix.sau.edu)
# 7/28/95
#
# Mailer.cgi is a script that I always hear requests for. All it does
# is takes the entries from a FORM and e-mails them to anyone you
# specify in the form in a nice, readable format.
#
# USAGE
# You use this script my putting special fields into your HTML form.
# They are as follows:
#
#
# Who to send the results to. Multiple recipients will work fine.
#
# What the subject should be on the mail message send to recipients
#
# Who should be listed in the "Reply-To" field of the mail message.
#
# Inputs do not need to be hidden, but you'll probably want them
# that way.
# The default response to give the user is at the very end. Anything
# after __END__ will be put up as feedback. Edit as you wish. If you
# would like the responses to be sent in a specific format, you'll have
# to do that on your own.
#
# THINGS FOR YOU TO CHANGE
# ========================
# The sendmail variable tells the script how to find the mailer on your
# system. This should be the right path, but change it if you are not
# using the standard setup. It uses the -t option to specify the
# recipients in the content of the message with To: and Cc:
$SENDMAIL="/usr/lib/sendmail -t";
# The CHECK_EMPTIES variable decides whether an error should be returned
# if a field is left blank. If it is set to 1, an error message will
# be displayed. If it is set to 0, blank fields are acceptable.
$CHECK_EMPTIES=0;
# =========================
# END OF USER CONFIGURATION
print "Content-type: text/html\n\n";
sub ReadParse {
# slightly modified from the usual readparse
local (*in) = @_ if @_; local ($i, $loc, $key, $val);
if ($ENV{'REQUEST_METHOD'} eq "GET") { $in = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUEST_METHOD'} eq "POST")
{read(STDIN,$in,$ENV{'CONTENT_LENGTH'});}
@in = split(/&/,$in);
foreach $i (0 .. $#in) {
$in[$i] =~ s/\+/ /g; ($key, $val) = split(/=/,$in[$i],2);
$FOUND=0; foreach (@FIELDS) { $FOUND=1 if ($key eq $_); }
if (($key ne 'TO')&&($key ne 'SUBJECT')&&($key ne 'REPLY-TO')&&($FOUND==0))
{ push(@FIELDS,$key); }
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val; } return 1; }
&ReadParse;
foreach (@FIELDS) {&MissingInfo if (($in{$_} eq '')&&($CHECK_EMPTIES==1));}
$SUBJECT=$in{'SUBJECT'}; delete $in{'SUBJECT'};
$REPLYTO=$in{'REPLY-TO'}; delete $in{'REPLY-TO'};
# split up the "to" names for multiple recipients
$TO=$in{'TO'}; @TO=split('\0',$TO);
# Open Sendmail and do our thing
open (SENDMAIL,"| $SENDMAIL") || die "Ain't Gonna Happen";
print SENDMAIL "To: @TO[0]\n";
if ($#TO > 0) { foreach (1..$#TO) { print SENDMAIL "Cc: @TO[$_]\n"; }
delete $in{'TO'}; }
print SENDMAIL "Subject: $SUBJECT\n";
print SENDMAIL "Reply-To: $REPLYTO\n";
# Display each field and responses
foreach (@FIELDS) {
$in{$_}=~ s/\0/\n\n * /g;
print SENDMAIL "---------------------------------------------------\n";
print SENDMAIL "Input Field: $_\n";
print SENDMAIL "Response:\n * $in{$_}\n";
}
print SENDMAIL "---------------------------------------------------\n";
close(SENDMAIL);
# Read in the response and print it.
undef $/; $_=; print;
# What to display as the "missing information" error
sub MissingInfo {
print <Error
Error: Fields left empty
You are required to fill in all the fields in this response form.
Please go back and fill in the fields with missing information.
EOF
exit(0);
}
# Everything down here is the default response.
__END__
Thank You
Thank You!
Thanks for responding to this form. Your responses have been mailed to
the correct person.