WWW Email program required

WWW Email program required

Post by Phillip Krokid » Wed, 26 Apr 1995 04:00:00



Hi guys,

I want to include am email program in my httpd cgi-bin directory
to process input from WWW order forms. Any suggestions where
I could get one that doesn't need any modifying and can handle
differently formatted order forms (ie. different information fields).

I tried a program called cgiemail but that gives sendmail errors.
I also looked at a program called email which worked but requires
customising for differently formatted order forms.

Thanks in advance

 
 
 

WWW Email program required

Post by Clay Helbe » Wed, 26 Apr 1995 04:00:00


Phillip Krokidis (p...@iaccess.com.au) wrote:

: Hi guys,

: I want to include am email program in my httpd cgi-bin directory
: to process input from WWW order forms. Any suggestions where
: I could get one that doesn't need any modifying and can handle
: differently formatted order forms (ie. different information fields).

: I tried a program called cgiemail but that gives sendmail errors.
: I also looked at a program called email which worked but requires
: customising for differently formatted order forms.

The following Perl script was posted to the HTML-authors-guild email list
this week. Credit for it goes to David Weaver.

If you do a lot of HTML writing, you might consider joining the guild.
For more info, see http://www.mindspring.com/guild/.

                                                --Clay

From html-authors-guild-ow...@list.Stanford.EDU Fri Apr 21 00:26:07 1995
Return-Path: <html-authors-guild-ow...@list.Stanford.EDU>
Date: Thu, 20 Apr 1995 21:42:10 -0500
To: html-authors-gu...@list.Stanford.EDU
From: webpa...@i-link.net (PAGES)
Subject: A script for the Guild
Sender: html-authors-guild-ow...@list.Stanford.EDU
Reply-To: html-authors-gu...@list.Stanford.EDU

Hi there and many thanks for your responses to the CGI request!

I've had a number of personal requests for some code that will take a form,
do a little validation, generate some e-mail, and provide a thank you
screen.  (this script also writes to a datalog and tells you if some needed
elements of the form are incomplete)
This code is not as compact as possible and you will see items reused in the
various sections so it's easier for errors to slip in BUT, this makes it a
whole lot easier to read and see what the code is doing.  I took this from a
project I'm finishing up and I have changed filenames and directories to
protect the innocent.

The script uses form elements with the following names:
'ItemInfo1'
'ItemInfo2'
'ItemInfo3'
'AGE'
'PersonType'
'username'
'realname'
'address'
'city'
'state'
'zip'
'country'
'telephone'
'comments'

The script also uses the new imagemap program.(which I like since I don't
have to bother my sysadmin all the time.)  You can info on it at:
http://hoohoo.ncsa.uiuc.edu/docs/setup/admin/imagemap.html  
(Still having problems getting to hoohoo)
Select the link to the new imagemap info.

Here's the PERL

Cheers,
David Weaver

----cut this line out----
#!/usr/local/bin/perl -- -*-perl-*-

#HTML Writers Guild Processing form for handling a response form.
#provide as is.  Give the Writers Guild some credit for this code!
#This is not an elegant script but it is easier to follow the
#program flow of this script than some of the more compact scripts
#I have seen.
#-------------- Define fairly-constants-------------------
#
# where does the data go?
$home = "/u/userdirectory";
$logfile = "$home/databases/subdirectory/whateverlog.listing";

# This should match the mail program on your system.
$mailprog = '/usr/lib/sendmail';

# Where to send the mail
$recipient = 'customerrelati...@bigcompany.com';

#-------------- Do the work -------------------
#
# Open the logfile defined above
&OpenLog;

# Read the data from the form and parse
&ParseInput;

#If the comments (or whatever) are blank, then give a "blank form" response
&blank_response unless $FORM{'username'} && $FORM{'realname'};

# Send Form Information to $recipient
&SendMail;

#Print to the log
&PrintLog;

#Print to the screen
&PrintScreen;

exit;

# ------------------------------------------------------------
# subroutine if a necessary field is blank then send this response
sub blank_response
{
   print "Content-type: text/html\n\n";
   print "<!--error2.html -->\n";
   print "<HTML><HEAD>\n";
   print "<TITLE> Incomplete Response Form </TITLE>\n";
   print "<LINK REV=MADE HREF=mailto:per...@domain.com>\n";
   print "</HEAD>\n";
   print "<BODY>\n";
   print "<h1><img alt=[Logo]  src=/subdirectory/image.gif>\n";
   print " Incomplete Response Form </H1><hr>\n";
   print "Your form appears to be missing some required information, and thus ";
   print "was not sent to the Big Company.  Your registration is important
to us,";
   print "so please try again.</a><p><HR>";
   print "<P><h5><a
href=/cgi-bin/nimagemap/subdirectory/theimagemapfile.map>\n";
   print "<img border=0 alt=[Menu Bar] src=/subdirectory/animagemap.gif
ismap></a></h5>\n";
   print "<br>\n";
   print "All contents Copyright &#169; 1995, Big Company. \n";
   print "All Rights Reserved.<br>\n";
   print "Send e-mail to <a
href=/subdirectory/commentform.html>comme...@www.bigcompany.com</a></h5>\n";
   print "</BODY>\n";
   print "</HTML>\n";
   exit 1;

}

# ------------------------------------------------------------
# send e-mail to receipent
sub SendMail
{
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "Subject: Web Form Response\n\n";
print MAIL  "The following information was collected:\n\n";
print MAIL "   ItemInfo1:  $FORM{'ItemInfo1'}\n";
print MAIL "   ItemInfo2:  $FORM{'ItemInfo2'}\n";
print MAIL "   ItemInfo3:  $FORM{'ItemInfo3'}\n";
print MAIL "         AGE:  $FORM{'AGE'}\n";
print MAIL "  PersonType:  $FORM{'PersonType'}\n";
print MAIL "    username:  $FORM{'username'}\n";
print MAIL "    realname:  $FORM{'realname'}\n";
print MAIL "Mail Address:  $FORM{'address'}\n";
print MAIL "        city:  $FORM{'city'}\n";
print MAIL "       state:  $FORM{'state'}\n";
print MAIL "         zip:  $FORM{'zip'}\n";
print MAIL "     country:  $FORM{'country'}\n";
print MAIL "       phone:  $FORM{'telephone'}\n";
print MAIL "    comments:  $FORM{'comments'}\n";
print MAIL "\n------------------------------------------------------------\n";
print MAIL "  Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "      Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
print MAIL "        Time/Date:",`date`;
print MAIL "\n------------------------------------------------------------\n";
close (MAIL);
return 1;
}

# ------------------------------------------------------------
#puts data in a file
sub PrintLog
{
print DATAlog "realname:  $FORM{'realname'}\n";
print DATAlog "Subject: Web Form Response\n\n";
print DATAlog  "The following information was collected:\n\n";
print DATAlog "   ItemInfo1:  $FORM{'ItemInfo1'}\n";
print DATAlog "   ItemInfo2:  $FORM{'ItemInfo2'}\n";
print DATAlog "   ItemInfo3:  $FORM{'ItemInfo3'}\n";
print DATAlog "         AGE:  $FORM{'AGE'}\n";
print DATAlog "  PersonType:  $FORM{'PersonType'}\n";
print DATAlog "    username:  $FORM{'username'}\n";
print DATAlog "    realname:  $FORM{'realname'}\n";
print DATAlog "Mail Address:  $FORM{'address'}\n";
print DATAlog "        city:  $FORM{'city'}\n";
print DATAlog "       state:  $FORM{'state'}\n";
print DATAlog "         zip:  $FORM{'zip'}\n";
print DATAlog "     country:  $FORM{'country'}\n";
print DATAlog "       phone:  $FORM{'telephone'}\n";
print DATAlog "    comments:  $FORM{'comments'}\n";
print DATAlog "\n--------------------------------------------------------\n";
print DATAlog "  Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print DATAlog "      Remote host: $ENV{'REMOTE_HOST'}\n";
print DATAlog "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
print DATAlog "        Time/Date:",`date`;
print DATAlog "\n--------------------------------------------------------\n";
close (DATAlog);
return 1;

}

# ------------------------------------------------------------
# subroutine puts data collected in form back on screen
sub PrintScreen
{
print "Content-type: text/html\n\n";
print "<!--thanks.html -->\n";
print "<HTML><HEAD>\n";
print "<TITLE> Your Comments Have Been Sent</TITLE>\n";
print "<LINK REV=MADE HREF=mailto:per...@domain.com>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<h1><img alt=[Logo]  src=/subdirectory/image.gif>\n";
print "Thank You for Your Comments </H1><hr>\n";
print <<"EOF"
Thank you for your comments. For additional information please write
to Big Company at:
<DD>  Big Company
<DD>  Attn: Internet Resource Contact
<DD>  54 Main Street
<DD>  Anytown, Tx
</DL>
<hr>
<P>
EOF
;
print "<P><h5><a href=/cgi-bin/nimagemap/subdirectory/theimagemapfile.map>\n";
print "<img border=0 alt=[Menu Bar] src=/subdirectory/animagemap.gif
ismap></a>\n";
print "<br>\n";
print "All contents Copyright &#169; 1995, Big Company \n"; print "All
Rights Reserved.<br></h5>\n";
print "</BODY>\n";
print "</HTML>\n";
return 1;

}

#---------------- Open log file -----------------------------
# open the logfile to write to, if there is a problem display an error message
sub OpenLog
{
unless (open(DATAlog, ">>$logfile")) {
   $err = $!;
   print "Content-type: text/html\n\n";
   print "<!--error3.html -->\n";
   print "<HTML><HEAD>\n";
   print "<TITLE> Logging Form Error </TITLE>\n";
   print "<LINK REV=MADE HREF=mailto:per...@domain.com>\n";
   print "</HEAD>\n";
   print "<BODY>\n";
   print "<h1><img alt=[Logo]  src=/subdirectory/image.gif>\n";
   print " Logging Form Error </H1><hr>\n";
   print "$0: cannot open $logfile: error code $err\n";
   print "uid, gid = $<, $(\n";
   print "<P><h5><a
href=/cgi-bin/nimagemap/subdirectory/theimagemapfile.map>\n";
   print "<img border=0 alt=[Menu Bar] src=/subdirectory/animagemap.gif
ismap></a></h5>\n";
   print "<br>\n";
   print "All contents Copyright &#169; 1995, Big Company\n";
   print "All Rights Reserved.<br>\n";
   print "</BODY>\n";
   print "</HTML>\n";
   exit 1;

}
return 1;
}

#--------------- Get the input -------------------------------
# Get the input from the form and parse it putting it in the $FORM array
sub ParseInput
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    # Not a big deal when using sendmail, but very important
    # when using
...

read more »