...

View Full Version : Script check !!!



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" ;

wap3
08-30-2002, 06:16 PM
Hi

Can someone please take a look at this. Im kind of desperate, as I need it working. Just see if there is any reason why it should not work ??

Thanks :thumbsup:

Inci
08-30-2002, 09:08 PM
Hello,

the first thing i noted:
$MailProgram = '/usr/sbin/sendmail-t';
which is completely wrong -
$MailProgram = '/usr/sbin/sendmail -t';

other thing i noted:
$MailProgram .= ' -t' if $MailProgram =~ /sendmail\Z/; # This line adding ' -t ' to sendmail when it's just /usr/sbin/sendmail - but you have defined your sendmail with -t at the top why to add this line?

hope this will help you

wap3
08-31-2002, 08:36 AM
woooohhhhhhhhoooooooooooooo

Yes thankyou Inci

Your brilliant. That fixed it. Ah thankyou so much man, I really really appreaciate it.

wooooohhhhhhhooooooooooooooooooo

Thankyou

:D :thumbsup:

wap3
08-31-2002, 02:40 PM
Hi everyone,

I was just wandering if it is possible to add an autorespond function to this script. After the form details have been sent to us, an e-mail is then sent out using the e-mail field as the 'to' value.

Any ideas on this ??

Thanks :thumbsup:

Mouldy_Goat
08-31-2002, 05:02 PM
You could just reuse the same mail-sending code again, just with different parameters.

wap3
08-31-2002, 05:20 PM
Ok, I have tried that but it dosen't work. It will send the form data to our e-mail, but its not generating the autoreply.

Any ideas on why its not doing it ??

Here is the code I have got:

#!/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@oursite.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;
}
}

#-------INITIATES CHECK AUTHORIZED AND PARSE FUNCTION-------------------------------

Parse;

#-------STARTS TO WRITE THE EMAIL----------------------------------------------------

$subject = 'Website request for brochure';

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}
Address: $fields{Address}
Town: $fields{Town}
County: $fields{County}
Postcode: $fields{Postcode}
Number: $fields{Telephone}
E-mail: $fields{EMail}

------------------------------------------------------------
------------------------------------------------------------
IP: $ENV{REMOTE_ADDR}
Form: $ENV{HTTP_REFERER}
------------------------------------------------------------
------------------------------------------------------------
TO_END

close MAIL;

#--------Autoresponder----------------------------------------------------------

open MAIL,"|$MailProgram";
print MAIL <<TO_END;
To: $fields{EMail}
From: $OurEmail
Subject: Autoresponder
Content-Type: text/plain; charset="us-ascii"

------------------------------------------------------------
The body of the e-mail autoresponder is written here

------------------------------------------------------------
TO_END

close MAIL;

print "Location: http://www.oursite.co.uk\n\n";

Mouldy_Goat
08-31-2002, 08:09 PM
Worked fine for me... are you sure you've got the TO_END markers on a line by themselves with nothing like spaces immediately after?

Also I didn't check, but I got rid of it for testing, but perhaps the script is throwing up warnings..? Hmm... they'd probably get printed to the errorlog anyway..

I didn't use any forms though, I just hardcoded some values in.

wap3
09-01-2002, 12:14 PM
No it still doesn't work. I checked for any extra spaces and that and it was fine. Its got to be something to do with the autorespond bit. Thats the only bit not being generated.

Any more ideas anyone ??

Thanks :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum