CGI problem

by Kef Moulton <kef(at)desoto.net>

 Date:  Sat, 15 Jul 2000 11:57:32 -0400
 To:  hwg-basics(at)hwg.org
  todo: View Thread, Original
Hi,
I've been playing around with a cgi script to send an email from a form 
submission.  Although the html file calls the cgi, it won't return the 
email.  Please tell me what is wrong!  The script is below.  Thanks for 
your help.
Kef



#!/usr/bin/perl
#This first part of the program splits up our data and gets it
#ready for formatting and mailing.
   $i=0;
   read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
   @pairs=split(/&/,$temp);
   foreach $item(@pairs)
    {
     ($key,$content)=split(/=/,$item,2);
     $content=~tr/+/ /;
     $content=~s/%(..)/pack("c",hex($1))/ge;
     $fields{$key}=$content;
     $i++;
     $item{$i}=$key;
     $response{$i}=$content;
    }

#Re-assign a couple of variables for readability reasons
     $send_to = $fields{MAIL_TO};
     $form_id = $fields{FORM_NAME};
     $msg_from = $fields{E_MAIL};


#Set up our HTML Result Form
    print "Content-type: text/html\n\n";
    print "<HTML>\n";
    print "<HEAD>\n";
    print "<TITLE>Information submission result</TITLE>\n";
    print "</HEAD>\n";
    print "<BODY BGCOLOR=#FFFFFF LINK=#4133EF ALINK=FF0000 VLINK=#FF0000>\n";
    print "<CENTER>\n";

    if ($SEND_MAIL="Y")
      {
        open (MAIL, "|$mail_program = '/usr/sbin/sendmail'") ||
             die "Unable to run mail program\n";
print MAIL <<__STOP_OF_HEADER__;
To: $send_to
From: $msg_from
Subject: $form_id RESPONSE

__STOP_OF_HEADER__
      }

    print "<H1>Your Request has been Submitted!</H1>\n";
    print "<A HREF=$ENV{'HTTP_REFERER'}>\n";
    print "<B>CLICK HERE!</B></A> To return to the previous page<P>\n";
    print "</CENTER>\n";
    print "<B>Here is the information you sent:</B><P>\n";
    print "<PRE>";
    print "<HR>\n";
    print "      SUBMISSION FORM: $form_id\n";
    print "      E-MAIL TARGET:   $send_to\n";
    print "<HR>\n";

    $i=1;
      while ( $item{$i} gt " ")
        {
          if ($SEND_MAIL="Y")
            {
              print MAIL "      $item{$i}:   $response{$i}\n";
            }
          print "      $item{$i}:   $response{$i}\n";
          $i++;
        }
    print "</PRE>";
    print "<HR>\n";
    print "</BODY>\n";
    print "</HTML>\n";

#CLOSE THE MAIL PROGRAM IF WE ARE MAILING
    if ($SEND_MAIL="Y")
       {
          close (MAIL);
       }

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA