On Sep 12, 2004, at 8:20 PM, John Horner wrote:

Any ideas? Here's a test script which runs without any problems, but no email is sent (or, to be logical, no email is received):

#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$mailprog = '/usr/sbin/sendmail -i -t';
open(MAIL,"|$mailprog") || die "$!";
print MAIL "To: [EMAIL PROTECTED]" || die "$!";
print MAIL "From:  [EMAIL PROTECTED]" || die "$!";
print MAIL "Subject: Test of Email Script\n\n"|| die "$!";
print MAIL "Test of Email Script\n"|| die "$!";
close (MAIL) || die "$!";
print "Content-type:text/html\n\n";
print "ran with no problems?";

Ouch! That's very sendmail-specific, and you'll be in trouble if you need to switch to a different mailer. I'd suggest a mailer-agnostic approach using Mail::Sendmail. (It's name is derived from what it does - i.e. it sends mail - rather than the name of a specific mailer.)


#!/usr/bin/perl -w

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;

my %mail = (
        'To'    =>           '[EMAIL PROTECTED]',
        'From' =>            '[EMAIL PROTECTED]',
        'Subject' => 'Email test',
        'Message' => 'This is a test. If this were a real email...',
);

sendmail(%mail) or die($Mail::Sendmail::error);

print CGI::header('text/plain'), 'No problems';

sherm--



Reply via email to