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!

use warnings;
use strict;
print <<EOF;
Content-type: text/plain

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

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


Copyright © Ben Bullock 2009-2023. 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