Net::SMTP problem

M

Matt

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('(e-mail address removed)');
$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
 
G

Graham Drabble

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 = '(e-mail address removed)'

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('(e-mail address removed)');
$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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top