Sending mail from a web page using a cgi-bin program
To send mail from a cgi-bin program, you should keep the following
points in mind:
Make sure cgi-bin execution is enabled for your account. You will
need an account type that includes cgi-bin support.
Invoke the /usr/sbin/sendmail program directly, so you can
format all headers.
Set an Errors-To: header so any bounced messages will
properly get back to you.
Below is sample perl code for sending mail. It assumes
you are using perl revision 5.
## ****** BEGIN SAMPLE PERL CODE TO SEND MAIL
# When this code is entered, the following variables must already be set:
# $to recipient, or comma-separated list of recipients
# $from desired From: line
# $errors address to which delivery errors should be sent; may be
# same as $from
# $subject desired Subject: line
# Invoke sendmail as a subprocess. -t means read addressees from
# standard input. -oi means don't let a single dot terminate input.
# -f sets envelope sender for error bounces.
if (! open(SENDMAIL, "|/usr/sbin/sendmail -f $errors -oi -t")) {
warn "error invoking sendmail: $!\n";
} else {
# send headers to sendmail, must end with empty line
print SENDMAIL <
}