wap3
08-29-2002, 04:29 PM
Hi eveyone,
I was just wandering if someone could look at this script and tell me if there is anything wrong with it. I have it on my site, when i sumbit the form its attached to, it doesn't give me any errors and then redirects me to the page it should. But it doesn't appear to be generating any e-mails, cause none have come through.
Anyway can you see if there is anything wrong with it.
Thanks
#!/usr/local/bin/perl - w
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# CGI SCRIPT FOR PROCESSING THE E-MAIL FORM ON OUR WEBSITE
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#Location of sendmail on server
$MailProgram = '/usr/sbin/sendmail-t';
#Email address to use for sending results
$OurEmail = 'ourmail@ourcompany.co.uk';
sub ErrorHTML {
#Error handler
my $eh = join '<li>',@_;
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<title>Notice : Error</title>
</head>
<body>
<h4>Notice:</h4><ul><li>$eh</ul>
</body>
</html>
~;
exit;
}
#-------------------------------------------------------------------------------------
#STARTS PROCESSING THE FORM DATA HERE
#-------------------------------------------------------------------------------------
sub Parse {
#Parse form submission sent by user
my $buffer;
ErrorHTML('Form must use method "POST"') unless ($ENV{REQUEST_METHOD} eq 'POST');
read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
my @data = split(/&/,$buffer);
for(@data) {
$_ =~ tr/+/ /;
my ($n,$v) = split(/=/,$_);
$n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/\<(.*?)embed/\<$1\_e_m_b_e_d_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)object/\<$1\_o_b_j_e_c_t_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)script/\<$1\_s_c_r_i_p_t_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)applet/\<$1\_a_p_p_l_e_t_\(mailer_robot_edited\)/sig;
$fields{$n} = $v;
}
}
#--------DISCARDS EXTRA SPACES FROM THE FORM INPUT-------------------------------------
sub DiscardExtraSpaces {
my $s=$_[0];
$s=~s/\A\s+//;
$s=~s/\s+\Z//;
$s=~s/\s\s+/ /g;
return $s;
}
#-------INITIATES PARSE FUNCTION-------------------------------
Parse;
#-------STARTS TO WRITE THE EMAIL----------------------------------------------------
$MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/;
$fields{FirstName} = DiscardExtraSpaces($fields{FirstName});
$subject = 'Website feedback form submission';
open MAIL,"|$MailProgram";
print MAIL <<TO_END;
To: $OurEmail
From: $fields{EMail} <"$fields{FirstName}""$fields{LastName}">
Subject: $subject
Content-Type: text/plain; charset="us-ascii"
Title: $fields{title}
First Name: $fields{FirstName}
Last Name: $fields{LastName}
Telephone: $fields{Telephone}
E-mail: $fields{EMail}
Topic: $fields{Topic}
------------------------------------------------------------
Comments: $fields{Comments}
------------------------------------------------------------
------------------------------------------------------------
IP: $ENV{REMOTE_ADDR}
Form: $ENV{HTTP_REFERER}
------------------------------------------------------------
------------------------------------------------------------
TO_END
close MAIL;
print "Location: http://www.oursite.co.uk\n\n" ;
I was just wandering if someone could look at this script and tell me if there is anything wrong with it. I have it on my site, when i sumbit the form its attached to, it doesn't give me any errors and then redirects me to the page it should. But it doesn't appear to be generating any e-mails, cause none have come through.
Anyway can you see if there is anything wrong with it.
Thanks
#!/usr/local/bin/perl - w
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
# CGI SCRIPT FOR PROCESSING THE E-MAIL FORM ON OUR WEBSITE
#--------------------------------------------------------------------------------
#--------------------------------------------------------------------------------
#Location of sendmail on server
$MailProgram = '/usr/sbin/sendmail-t';
#Email address to use for sending results
$OurEmail = 'ourmail@ourcompany.co.uk';
sub ErrorHTML {
#Error handler
my $eh = join '<li>',@_;
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<title>Notice : Error</title>
</head>
<body>
<h4>Notice:</h4><ul><li>$eh</ul>
</body>
</html>
~;
exit;
}
#-------------------------------------------------------------------------------------
#STARTS PROCESSING THE FORM DATA HERE
#-------------------------------------------------------------------------------------
sub Parse {
#Parse form submission sent by user
my $buffer;
ErrorHTML('Form must use method "POST"') unless ($ENV{REQUEST_METHOD} eq 'POST');
read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
my @data = split(/&/,$buffer);
for(@data) {
$_ =~ tr/+/ /;
my ($n,$v) = split(/=/,$_);
$n =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$v =~ s/\<(.*?)embed/\<$1\_e_m_b_e_d_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)object/\<$1\_o_b_j_e_c_t_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)script/\<$1\_s_c_r_i_p_t_\(mailer_robot_edited\)/sig;
$v =~ s/\<(.*?)applet/\<$1\_a_p_p_l_e_t_\(mailer_robot_edited\)/sig;
$fields{$n} = $v;
}
}
#--------DISCARDS EXTRA SPACES FROM THE FORM INPUT-------------------------------------
sub DiscardExtraSpaces {
my $s=$_[0];
$s=~s/\A\s+//;
$s=~s/\s+\Z//;
$s=~s/\s\s+/ /g;
return $s;
}
#-------INITIATES PARSE FUNCTION-------------------------------
Parse;
#-------STARTS TO WRITE THE EMAIL----------------------------------------------------
$MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/;
$fields{FirstName} = DiscardExtraSpaces($fields{FirstName});
$subject = 'Website feedback form submission';
open MAIL,"|$MailProgram";
print MAIL <<TO_END;
To: $OurEmail
From: $fields{EMail} <"$fields{FirstName}""$fields{LastName}">
Subject: $subject
Content-Type: text/plain; charset="us-ascii"
Title: $fields{title}
First Name: $fields{FirstName}
Last Name: $fields{LastName}
Telephone: $fields{Telephone}
E-mail: $fields{EMail}
Topic: $fields{Topic}
------------------------------------------------------------
Comments: $fields{Comments}
------------------------------------------------------------
------------------------------------------------------------
IP: $ENV{REMOTE_ADDR}
Form: $ENV{HTTP_REFERER}
------------------------------------------------------------
------------------------------------------------------------
TO_END
close MAIL;
print "Location: http://www.oursite.co.uk\n\n" ;