Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Net::SMTP problem (http://www.velocityreviews.com/forums/t899705-net-smtp-problem.html)

Matt 08-30-2006 07:00 PM

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


Graham Drabble 09-01-2006 11:37 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57