I am using Perl5.6 on Windows XP..and an Apache-Tomcat server to host my web page. Though I am able to send mails using Mail::Sendmail in perl, I am not able to do so using CGI from browser.
Here is the Perl script which sends mail successfully....
use Mail::Sendmail;
%mail = ( To => 'somebody@somewhere',
From => 'blah@blah',
Subject =>'sample subject',
Message => "sample message"
);sendmail(%mail) or die("mail NOT sent \n\nERROR DETAILS: \n". $Mail::Sendmail::error);
print "Log says:\n", $Mail::Sendmail::log;
But when i am using this in my CGI script and open that cgi page from my browser, it gives an error..
Here is my CGI script which is almost same to previous one.
use CGI;
use Mail::Sendmail;print "Content-Type: text/html\n\n";
print "<html> <head>\n";
print "<title>testmail</title>";
print "</head>\n";
print "<body>\n";
%mail = ( To => 'somebody@somewhere',
From => 'blah@blah',
Subject =>'sample subject',
Message => "sample message"
);
if(sendmail(%mail)) {print "<p>Success!";} else { print("mail NOT sent \n\nERROR DETAILS: \n". $Mail::Sendmail::error);}
print "<p>Log says:<p>\n". $Mail::Sendmail::log;
print "</body> </html>\n";
unfortunately i have never seen that "Success" :( :(
Here is the **latest** ouput in internet explorer i have seen...
mail NOT sent ERROR DETAILS: socket failed (Unknown error)
Log says:
Mail::Sendmail v. 0.79 - Tue Sep 18 15:00:45 2007 Date: Tue, 18 Sep 2007 15:00:45 +0530
...for mail server i am using Default SMTP virtual server in IIS...looking at the error type socket failed (Unknown error), I am at sea as to what after should I run! Is it Perl(nope ..i don think so!) or if is it socket error? (then what is the actual error? how can I fix an error which is termed as Unknown :( :( )
..
PLZZZZZZZZZ Help me out .. :( :( :(
i would try using something like the Socket or IO::Socket perl packages to create a test socket directly in your cgi script instead of buried in the Mail::Sendmail package and see if you can get a better error message.
you might also try another mail package such as Mail::Sender to see if it works better on xp.
use CGI;
use Mail::Sender;
print "Content-Type: text/html\n\n";
print "<html> <head>\n";
print "<title>testmail</title>";
print "</head>\n";
print "<body>\n";
$sender = new Mail::Sender {
smtp => '{ip address}',
from => 'test@test',
on_errors => undef,
}
or print "<p>Can't create the Mail::Sender object: <br>$Mail::Sender::Error\n";
$sender->Open({
to => 'blah@blah',
subject => 'Hi there'
})
or print "<p>Can't open the message: <br>$sender->{'error_msg'}\n";
$sender->SendLineEnc("1st line");
$sender->SendLineEnc("\n2nd line");
$sender->Close()
or print "<p>Failed to send the message: <br> $sender->{'error_msg'}\n";
print "</body> </html>\n";
...and the output is...
Can't open the message:
socket() failed: $^E
Failed to send the message:
Connection not established
..still can't get what the error is! :(
your ultimate solution should be to use sendmail which is a more standard perl way to do it.
sendmail comes standard on *nix-type systems, but i'm sure you can find some "sendmail for windows" solutions if you search carefully.
for mail server i am using Default SMTP virtual server in IIS...
I have not used these modules but have done a lot of mailing from IIS/other windows servers using a simple sockets subroutine. In most of these, there the method gethostbyname($smtp) is used ....
If $smtp is not defined, it never worked.
$smtp = 'mail.yourserver.com';
Is there somewhere the smtp mail server is supposed to be defined?
When you run the script from the command line it uses your logged on user name, and I'm assuming you have administrative rights.
When you run through CGI the scripts runs under IIS's user (IUSR_#*$!#*$!xx), which may not have permission to send mail on your Exchange server?
Have you done CGI/sendmail on that server before?