mail-form-demo.pl: CGI program initiated by HTML form in
mail-form.html
#!/usr/local/bin/perl
#
# Demo Script for AusWeb95 Paper example
# Copyright (c) Martin Gleeson & Tina Westaway, March 1995
#
$mail_program="/usr/bin/mail";
$subject="AusWeb95 Demo Response";
if ( $ENV{REQUEST_METHOD} eq "POST") {
# It's the POST method, so print content length and coded input from
# STDIN. Then decode it and print again.
$len = $ENV{CONTENT_LENGTH};
while( <STDIN> )
{
$postinput .= $_;
if( length($postinput) >= $len ){last;}
}
# change field delimiter from & to "|F|"
$postinput =~ s/&/|F|/g;
$postinput =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; # decode encoded input
$posted=$postinput;
$posted =~ s/\+/ /g; # Change +'s to spaces
@QUERY_LIST = split( /\|F\|/, $posted);
foreach $item (@QUERY_LIST) {
($param, $value) = split( /=/, $item);
$QUERY_ARRAY{$param} .= $value;
$QUERY_ARRAY{$param} .= " ";
if ( $param eq "name") { $name=$QUERY_ARRAY{$param}; }
if ( $param eq "department") { $department=$QUERY_ARRAY{$param}; }
if ( $param eq "email") { $email=$QUERY_ARRAY{$param}; }
if ( $param eq "phone") { $phone=$QUERY_ARRAY{$param}; }
if ( $param eq "date") { $date=$QUERY_ARRAY{$param}; }
}
# Check form validity and email it
#
# Reject form if any of the fields are empty
#
if($name eq "" || $department eq "" || $email eq "" || $date eq "") {
print "<html><head><title>Email Rejected</title></head><body>
<h2><img src=/images/Email.GIF>Email Rejected</h2>
<p>Please be sure to fill out all the fields provided.
<hr><!-- ========================================== -->
<p>Applicant Name: $QUERY_ARRAY{'name'}<br>
Applicant Dept: $QUERY_ARRAY{'department'}<br>
Email Address: $QUERY_ARRAY{'email'}<br>
Items:\n $QUERY_ARRAY{'items'}<br>
Total: $QUERY_ARRAY{'total'}<br>
Suppliers: $QUERY_ARRAY{'suppliers'}<br>
Reasons: $QUERY_ARRAY{'reasons'}<br>
Advisor Name: $QUERY_ARRAY{'lite'}</p>
<hr><!-- ========================================== -->
</body></html>";
exit(0);
}
#
# Or if the email address doesn't have an "@" in it.
#
elsif( ! ($email =~ /@/ ) ) {
print "<html><head><title>Email Rejected</title></head><body>
<h2><img src=/images/Email.GIF>Email Rejected</h2>
<p>That email address is not valid or empty.<br>
You *must* enter an email address, and it must be of the form:<br>
<em>user</em>@<em>host.name.etc</em>.<br><br>
<hr><!-- ========================================== -->
<p>Applicant Name: $QUERY_ARRAY{'name'}<br>
Applicant Dept: $QUERY_ARRAY{'department'}<br>
Email Address: $QUERY_ARRAY{'email'}<br>
Items:\n $QUERY_ARRAY{'items'}<br>
Total: $QUERY_ARRAY{'total'}<br>
Suppliers: $QUERY_ARRAY{'suppliers'}<br>
Reasons: $QUERY_ARRAY{'reasons'}<br>
Advisor Name: $QUERY_ARRAY{'lite'}</p>
<hr><!-- ========================================== -->
</body></html>";
exit(0);
}
#
# Send the mail
#
else {
open(MAIL,"| $mail_program $email");
select(MAIL);
print "Subject: $subject\n";
print "Reply-To: $email ($name)\n";
print "From: $email ($name)\n";
print "[ This message was sent to the University of Melbourne ]\n";
print "[ WWW Group Development Server. It is not authenticated. ]\n\n";
print "Applicant Name: $QUERY_ARRAY{'name'}\n";
print "Applicant Dept: $QUERY_ARRAY{'department'}\n";
print "Applicant Email: $QUERY_ARRAY{'email'}\n";
print "Applicant Phone: $QUERY_ARRAY{'phone'}\n";
print "Application Date: $QUERY_ARRAY{'date'}\n";
print "--\nItems: $QUERY_ARRAY{'items'}\n";
print "--\nTotal: $QUERY_ARRAY{'total'}\n";
print "--\nSuppliers: $QUERY_ARRAY{'suppliers'}\n";
print "--\nReasons: $QUERY_ARRAY{'reasons'}\n";
print "--\nLite: $QUERY_ARRAY{'lite'}\n";
print ".\n";
close(MAIL);
select(STDOUT);
# send the HTML response
print "Content-type: text/html\n\n";
print "<html><head><title>Data Accepted</title></head><body>
<h2><img src=\"/images/Email.GIF\"> Data Accepted - Email Sent</h2>
<p>Your form has been accepted and email confirmation sent.
<p>Your data is as follows:
<hr><!-- ========================================== -->
<p>Applicant Name: $QUERY_ARRAY{'name'}<br>
Applicant Dept: $QUERY_ARRAY{'department'}<br>
Email Address: $QUERY_ARRAY{'email'}<br>
Items:\n $QUERY_ARRAY{'items'}<br>
Total: $QUERY_ARRAY{'total'}<br>
Suppliers: $QUERY_ARRAY{'suppliers'}<br>
Reasons: $QUERY_ARRAY{'reasons'}<br>
Advisor Name: $QUERY_ARRAY{'lite'}</p>
<hr><!-- ========================================== -->
</body></html>";
exit(0);
}
}
#
# If the form hasn't been put together properly, notify the user
#
else {
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Email Rejected</TITLE></HEAD><BODY>\n";
print "<p>This form should be referenced with a METHOD of POST<br>";
print "If you don't understand, see this:</p>";
print '<A HREF="http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html">Forms Overview</A>.<P>';
print "<P></BODY></HTML>";
}