A simple CGI sendmail script

This example program illustrates the use of sendmail to send an email using a Perl CGI script. Please substitute your own email address in the program before using it - I don't want your test mails!

#!/usr/local/bin/perl
use warnings;
use strict;
print <<EOF;
Content-type: text/plain

EOF
eval {
    open my $sendmail, "| /usr/bin/sendmail -oi -oeq -t" or die $!;
    print $sendmail <<EOF;
to: ben.bullock\@lemoda.net
Testing 1 2 3

EOF
    close $sendmail or die "Error closing sendmail: $!";
};
if ($@) {
    print "Error: $@\n";
}
else {
    print "OK.\n";
}

(download)


Copyright © Ben Bullock 2009-2019. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer