Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

I need your help.

I made this simple script for use with html forms.

#!/usr/bin/perl use Net::SMTP; use CGI qw(:standard); #---------------Configuration section----------------# $to="info\@domainname"; #---------------Configuration section ends-----------# #--------------Initialization section----------------# $name=param("name"); $surname=param("surname"); $subject=param("subject"); $comments=param("comments"); $company=param("company"); $phone=param("phone"); $fax=param("fax"); $email=param("email");; #--------------Initialization section ends-----------# ###### required fields check $check=1; if (!$name) {$check="0";} elsif (!$surname) {$check="0";} elsif (!subject) {$check="0";} elsif (!email) {$check="0";} else { ###### required fields check ends here $smtp = Net::SMTP->new('localhost'); $smtp->mail("Mail from Website"); $smtp->to("$to"); $smtp->data(); $smtp->datasend("FROM: Mail from Website\n"); $smtp->datasend("TO: $to\n"); $smtp->datasend("SUBJECT: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("NAME: $name\n"); $smtp->datasend("SURNAME: $surname\n"); $smtp->datasend("SUBJECT: $subject\n"); $smtp->datasend("COMMENTS:\n\n$comments\n\n"); $smtp->datasend("COMPANY: $company\n"); $smtp->datasend("PHONE: $phone\n"); $smtp->datasend("FAX: $fax\n"); $smtp->datasend("E-MAIL: $email\n"); $smtp->dataend(); $smtp->quit; } if ($check=="0") { print "Content-type: text/html;", "\n\n"; print << 'ERRORMSG'; <html> <head> <title> E-mail status </title> <style type="text/css"> P {font-family: Arial; font-size: 14pt;font-weight: bold; color: #353B +37;} </style> </head> <body bgcolor="#ffffff"> <table width="100%" height="100%"> <tr> <td align="center"><P><img src="images/error.jpg" border="0" h +space="0" vspace="0">Please Fill All REQUIRED Forms<br><br><P><img src="images/error.jpg" border="0" hspace="0" vspa +ce="0">Παρακαλώ συμπληρώσατε όλα τα απαιτούμενα πεδία</P></td> </tr> </table> </body> </html> ERRORMSG } else { print "Content-type: text/html;", "\n\n"; print << 'OKMSG'; <html> <head> <title> E-mail status </title> <style type="text/css"> P {font-family: Arial; font-size: 14pt;font-weight: bold; color: #353B +37;} </style> </head> <body bgcolor="#ffffff"> <table width="100%" height="100%"> <tr> <td align="center"><P><img src="images/ok.jpg" border="0" hspace=" +0" vspace="0"> Message sent successfully<br><br><img src="images/ok.jpg" bord +er="0" hspace="0" vspace="0">To E-mail σας στάλθηκε επιτυχώς</P> </td> </tr> </table> </body> </html> OKMSG }

When required fields are not filled response comes in a few seconds. But if everything is ok and mail is going to be sent response comes after 2 or more minutes.

Does anybody know where is my mistake ?

Thanks

Replies are listed 'Best First'.
Re: Net::SMTP - too much delay...
by Anonymous Monk on Aug 12, 2002 at 08:36 UTC

    This code is why there is so much spam. You have just let anyone in the world send email to anyone else.

    You don't Taint check, no warnings, no strict

    As for your answer use the debugger step through the code then find out where the delay is. As soon as you know where it is - Stop running this script and save us all a little spam

Re: Net::SMTP - too much delay...
by fsn (Friar) on Aug 12, 2002 at 09:12 UTC
    I can't see why it would take different amount of time depending on the message itself, so I can't answer that. Try running from commandline and see what happens. Now some nitpicking: Your From address is incorrect. It should contain a valid email address. It should at least look like:
    From: Mail from website <website@domain>
    As other monks have said so often before, use warning, use strict etc etc bla bla.

    As long as you don't take $to from the user I don't think there is any risk for spamming anyone but yourself, so I disagree with Anonymous Monks previous node. A bit more errorchecking, and checking for backticks and stuff wouldn't hurt though.

      I put Debug => 1 and try it from command line and the delay was about 15 seconds.This delay come from the IO::Hadle.

      I tried it a lot of times but the delay was 10-20 seconds.This 2 minute delay is mysterious.

      You are right for the FROM line. I fixed it.

      For the error handling ...etc... you are RIGHT. I must use error handling.

      Thanks fsn..
Re: Net::SMTP - too much delay...
by Anonymous Monk on Aug 12, 2002 at 08:30 UTC
    Sorry for the double post...

    Anonymous & Stupid Monk