|
Kaye and Geoff's web page documentation
Perl script to handle formatted emailAn email CGI can be simple and customised for one type of form, or generalised to handle almost any form, as is this example. The CGI is written in Perl and is assumed to be invoked from a web server running under Unix, since Unix system calls are used. The code splits the input into fields, using the ampersand (&) to determine where each new field starts. The hidden fields from the form are used to provide a subject line for the email, set the email address and the URL of a page to display after the form is submitted. To send the email, the script opens up an email process and writes directly to it. No return URL provided';
$incoming = Information not mailed";
$email = '';
}
if ($missing)
{
$email = '';
$message = "$missing field is required Information not mailed";
$url = '';
}
#
# mail the contents of the list
# use process as a filehandle and write the array to it
#
unless ($subject) { $subject = 'from WWW page'; }
if ($email)
{
open (MAILPROC, "|/bin/mail -s \"$subject\" $emailto");
print MAILPROC "Source=$ENV{REMOTE_HOST}\n\n";
print MAILPROC @itemlist;
close (MAILPROC);
}
#
# display the specified www page to return control to the user
# if none then mock one up
#
if ($url) { print "Location: $url\n\n"; }
else
{
print "Content-type: text/html \n\n";
print " Using this CGI has a number of advantages over a simple "mailto:" hardcoded in the HTML of the form:
This CGI could be modified to perform any number of additional tasks; it might:
Only minimal checking of the input is carried out in the code above. A working version of the program should validate all the input fields, especially the email address. This could include rejecting addresses with invalid characters, making sure that the format is correct (that there is one and only one '@', and no more than one '.' in a row, etc.) and checking to see if the domain is valid, and has associated MX records. |
|
Top Close |