![]() |
Net::SMTP problem
have a simple few lines of Perl I'm trying to run from a cgi program
to send some email. My code looks like: use Net::SMTP; my $email="mda\@x.com"; my $msg="hello tst\n"; $smtp = Net::SMTP->new('smtp.x.com');# or die "Unable to open the connection"; $smtp->mail('...@yahoo.com'); $smtp->to($email); $smtp->data($msg); $smtp->dataend(); $smtp->quit; When I run the code via command line it works. When I run it via a cgi program from a webpage I get when it dies on the SMTP->new line: Can't call method "mail" on an undefined value Everything I"ve searched for says it is because my script cannot contact the smtp server, but that's not the case because when I run it via the command line, it works fine. It looks like it has to be some permisssion thing, either in sendmail or apache. Any thoughts? Thanks |
Re: Net::SMTP problem
On 30 Aug 2006 "Matt" <mda@unb.ca> wrote in
news:1156964409.840792.180040@i42g2000cwa.googlegr oups.com: > have a simple few lines of Perl I'm trying to run from a cgi > program to send some email. > My code looks like: > use Net::SMTP; > my $email="mda\@x.com"; why not my $email = 'mda@x.com' Saves escaping the @. > my $msg="hello tst\n"; > $smtp = Net::SMTP->new('smtp.x.com');# or die "Unable to > open the connection"; Why comment out the or die()? that will only get called if the Net::SMTP->new() fails, surely you want some form of error handling there. > $smtp->mail('...@yahoo.com'); > $smtp->to($email); > $smtp->data($msg); > $smtp->dataend(); That isn't a valid mail message. You need some headers. > $smtp->quit; > > > When I run the code via command line it works. When I run it via a > cgi program from a webpage I get when it dies on the SMTP->new > line: Can't call method "mail" on an undefined value > Everything I"ve searched for says it is because my script cannot > contact the smtp server, but that's not the case because when I > run it via the command line, it works fine. It probably is that you can't connect to (rather than contact) the server. Most servers run IP based authorisation, the webserver may well not have permissions to use it. Find the SMTP server of your webspace. -- Graham Drabble http://www.drabble.me.uk/ |
| All times are GMT. The time now is 08:53 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.