The source code of mail.pl : #!/usr/bin/perl # Demo call of sendmail to be used a CGI script # Author: R Bland August 2001, with minor edits by SBJ # Important points: # # 1) The script must _run_ on a server offering a sendmail command. # Use the script's filename as a URL in a browser or WWW form, # as (for example) # http://shark.cs.stir.ac.uk/~abc01/mailrbl.pl # 2) As it stands, this script must be customized with the sender's # and receiver's email addresses - of course any of these could be # obtained from CGI parameters. # 3) This facility can easily be used to send unwanted mail. # You must not do this. Your scripts must be carefully and # responsibly written. # 4) As part of responsible use, you should make sure that the # user of one of your WWW forms cannot type-in data that will # cause unwanted mail to be sent. use strict ; # HTTP Header for the server: note two newlines print "Content-type: text/html\n\n" ; # HTML header for the browser print "<!DOCTYPE HTML PUBLIC " ."\"-//W3C//DTD HTML 4.0//EN\">\n" ; print "<HTML>\n" ; print " <HEAD>\n" ; print " <TITLE>sendmail from Perl</TITLE>\n" ; print " </HEAD>\n" ; print " <BODY>\n" ; print " <H1>sendmail from Perl</H1><HR>\n" ; my $sender = '???' ; # eg 'abc' my $receiverName = '???' ; # eg 'def' my $receiverAddress = '??????' ; # eg 'cs.stir.ac.uk' my $replyName = '???' ; # eg 'abc' my $replyAddress = '???????' ; # eg 'students.stir.ac.uk' (if that's abc's email server) print "Mailing $receiverName\@$receiverAddress ...<br>\n" ; # We have three parts: $command, $flags, $message # First, the command my $command = "/usr/sbin/sendmail" ; # # Now the flags: # -t specifies that To: etc are read from the message my $flags = "-t" ; # # The message is a single string. It contains # multiple lines enclosed in the lines # "<<EOF\n" # and # "EOF\n" ; my $message = "<<EOF\n" ."To: $receiverName\@$receiverAddress\n" ."Reply-to: $replyName\@$replyAddress\n" ."From: $sender\n" ."Subject: Long sentence from Shark\n" ."Of Man's first disobedience, and the fruit\n" ."Of that forbidden tree whose mortal taste\n" ."Brought death into the World, and all our woe,\n" ."With loss of Eden, till one greater Man\n" ."Restore us, and regain the blissful seat,\n" ."Sing, Heavenly Muse, that, on the secret top\n" ."Of Oreb, or of Sinai, didst inspire\n" ."That shepherd who first taught the chosen seed\n" ."In the beginning how the heavens and earth\n" ."Rose out of Chaos: or, if Sion hill\n" ."Delight thee more, and Siloa's brook that flowed\n" ."Fast by the oracle of God, I thence\n" ."Invoke thy aid to my adventurous song,\n" ."That with no middle flight intends to soar\n" ."Above th' Aonian mount, while it pursues\n" ."Things unattempted yet in prose or rhyme.\n" ."EOF\n" ; # Now concatenate the whole thing into a single string # and pass that string to the "system" function my $rc = 0xffff & system("$command $flags $message") ; printf "\"system\" call returned %#04x: <br>\n", $rc ; print "If the return code was 0000, then the message " ."should be on its way to " ."$receiverName\@$receiverAddress...<br>\n" ; print "... finished<br>\n" ; print " </BODY>\n" ; print "</HTML>\n" ;