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

Hi Monks, I have the same code which works fine on commandline but when i tried usuing with CGI on websever it always gives me the "Close failed! Connection not established". Any idea why this happens with CGI?I am trying to send mail with two attachment with some html message body

use Mail::Sender; my $recipients = 'test@some.com; my $sender = new Mail::Sender {smtp => smtpsome.com'}; if ($sender->OpenMultipart({from => 'some.com', to => $recipients, subject => "Test", subtype => 'related', boundary => 'boundary-test-1', type => 'multipart/related'}) > 0) { $sender->Attach( {description => 'html body', ctype => 'text/html; charset=us-ascii', encoding => '7bit', disposition => 'NONE', file => 'finalhtml.html' }); $sender->Attach( {description => 'ed\'s gif', ctype => 'application/vnd.ms-excel', encoding => 'base64', disposition => "inline; ", file => "One.xls" }); $sender->Attach( {description => 'ed\'s gif', ctype => 'application/vnd.ms-excel', encoding => 'base64', disposition => "inline; ", file => "two.xls" }); $sender->Close(1) or die "Close failed!$Mail::Sender::Error\n"; } else { die "Cannot send mail: $Mail::Sender::Error\n"; }

Replies are listed 'Best First'.
Re: Mail::Sender code doesnt work with CGI on webserver
by i5513 (Pilgrim) on Apr 18, 2012 at 05:39 UTC
Re: Mail::Sender code doesnt work with CGI on webserver
by mendeepak (Scribe) on Apr 18, 2012 at 06:42 UTC

    Mail::Sender has another option called MailFile and its syntax goes something like this

    MailFile([from [, replyto [, to [, smtp [, subject [, headers]]]]]], m +essage, file(s)) MailFile({[from => "somebody@somewhere.com"] [, to => "else@nowhere.com"] [...], msg => "Message", file => "File"})
    try the code out, don't know whether it will fix your problem.. Check this link for more details Mail::sender

Re: Mail::Sender code doesnt work with CGI on webserver
by Anonymous Monk on Apr 18, 2012 at 04:15 UTC
    Check logs, permissions, firewall, selinux, chrootjail ... things like that