Hello all,
So I'm having trouble using sendmail in a CGI script as the topic title says.
Here's what I'm trying to accomplish:
User fills out a form, submits it, my CGI script receives this data, emails it to me, then displays a "thank you" html page to the user. Here's a look at the code that calls sendmail:
-
unless (open (MESSAGE,"| /usr/sbin/sendmail -t")){
-
die "Can't open sendmail: $!";
-
}
-
print MESSAGE "To: $email\n" or die $!;
-
print MESSAGE "From: $FORM{Coach}\n" or die $!;
-
print MESSAGE "Reply-To: $FORM{Email}\n" or die $!;
-
print MESSAGE "Subject: Roster from $FORM{School}\n" or die $!;
-
print MESSAGE "\n" or die $!;
-
-
print MESSAGE "School: $FORM{School}\n" or die $!;
-
print MESSAGE "Coach: $FORM{Coach}\n" or die $!;
-
print MESSAGE "Invite: $FORM{Invite}\n" or die $!;
-
print MESSAGE "Date: $FORM{Date}\n\n" or die $!;
-
print MESSAGE "Roster for $FORM{Category}:\n" or die $!;
-
-
close (MESSAGE);
-
Here's what happens:
When my script executes, it displays the html page without error, but I never receive an email. I check my error log and this is what is shown:
[Sat Aug 1 07:08:35 2009 GMT] /path/to/roster.cgi: Use of uninitialized value in concatenation (.) at /full/path/to/Config.pm line 44.
sendmail:
I'm not really sure what, if anything, the first error has to do with what I am doing. Here is the snippet of code in question:
-
if ($< == $> and !$CONFIGURE) {
-
my $home = eval { (getpwuid($>))[7] } || $ENV{HOME};
-
$file = $home . "/.libnetrc"; ##### line 44 #####
-
$ref = eval { do $file } if -f $file;
-
%NetConfig = (%NetConfig, %{ $ref })
-
if ref($ref) eq 'HASH';
-
}
-
It looks like $home is still undefined after line 43, since $ENV{HOME} does not have a value?
The second error, which is simply "sendmail: ", has me a little confused, but I opened up the sendmail program and found where this error might be coming from:
-
# Connect to mail server
-
my $smtp = new My::Net::SMTP "127.0.0.1";
-
# Make sure it connected
-
if (!$smtp) {
-
if (@{ $My::Net::SMTP::getlines }) {
-
# Must have gotten an invalid response
-
&failed(5);
-
} else {
-
# Did not even get a response
-
print STDERR "sendmail: $!\n";
-
}
-
exit ($! || 4);
-
}
-
And the reason I think the error is a result of this block of code is because of the use of "sendmail: $!\n"
So I guess that means it is not connecting to the mail server? I've tried this CGI script on a different website and it works fine. Not sure what to do next! Please help!