#!/usr/bin/perl # (c) 2001-2008 Alexander Thomas # Simple e-mail form script. # This script is free to use. It may not be sold. # Use of this script is at your own risk. There is no guarantee # or liability whatsoever for fitness for any purpose. # # INSTRUCTIONS: # Fill in the correct values in the Parameter section below. # Make a form on your website with method "POST" and as action the # URL of this script on your server. (Of course this script must # have execute permissions.) # The form can contain the following fields (case sensitive). You can # easily fix the values for certain fields by making them hidden: # -from: the e-mail address of the sender # -sendername: the name of the sender # -carboncopy (checkbox): if this is checked, a copy of the message # will be sent to the address in 'from'. # -subject: subject of the mail # -nextpage: the page to be loaded after sending the mail. If empty, # the message itself will be displayed instead. # -message: the message itself # You can add custom fields by modifying the mail_it subroutine below. ################################################################## # # PARAMETER SECTION # Your system's e-mail program, typically either /usr/sbin/sendmail or # /usr/lib/sendmail $MAIL_PROGRAM='/usr/sbin/sendmail'; # The e-mail address to send the mails to. $RECIPIENT='YOUR@E-MAIL.HERE'; # If set, is where the script can be called from. You'll want to put # your domain name in here so that only you can run this script. # Leave off http:// and anything that may be omitted, like 'www.'. # Use () for no restrictions (not recommended!) @VALID_DOMAINS = ('YOUR-DOMAIN-HERE.com'); # Put a list here of IPs that should be blocked. You can also omit the # last parts, like '12.34.56.' or even '12.34.' to block domains. @BLOCKED_IPS = (); ################################################################## # # MAIL LAY-OUT # # You can tailor this to your own needs, e.g. add headers or markers. # Make sure not to remove essential headers like From, To and Subject, # and make sure the header section ends with \n\n. sub mail_it { $theMail = "To: $RECIPIENT\n"; $tmp = $fields{'from'}; if ($fields{'sendername'} ne "") { $tmp = "\"$fields{'sendername'}\" <$tmp>"; } $theMail .= "From: $tmp\n"; if($fields{'carboncopy'} eq 'on') { $theMail .= "Cc: $tmp\n"; } $theMail .= "Subject: $fields{'subject'}\n"; $theMail .= "Return-Path: <$fields{'from'}>\n"; $theMail .= "X-Http-Remote-Addr: $ENV{'REMOTE_ADDR'}\n"; $theMail .= "X-Http-Forwarded-For: $ENV{'HTTP_X_FORWARDED_FOR'}\n"; $theMail .= "X-Http-User-Agent: $ENV{'HTTP_USER_AGENT'}\n"; $theMail .= "X-Http-Referer: $ENV{'HTTP_REFERER'}\n\n"; $theMail .= "$fields{'message'}"; open(MZT,"|$MAIL_PROGRAM -t") || die "Unable to send mail: $^E"; print MZT $theMail; close(MZT); } # MAIN ########################################################### # This is where the script starts execution from &valid_page; &decode_vars; &test_required; &mail_it; if ($fields{'nextpage'} ne "") { print "Location: $fields{'nextpage'}\n\n"; } else { $theMail =~ s/</g; $theMail =~ s/>/>/g; print "Content-type: text/html\n\n\n
$theMail\n"; } exit; ################################################################## # You can extend this function to test for a mandatory answer on # a simple question, to thwart spambots. You could also use a # 'mouse trap' field, which must be empty, and reject messages # where this field is not empty. sub valid_page { $DN = $ENV{'HTTP_REFERER'}; if ($#VALID_DOMAINS + 1 eq 0 || $DN eq "") { return; } foreach $referer (@VALID_DOMAINS) { if ($DN =~ m|https?://([^/]*)$referer|i) { $referer_ok = 1; last; } } if ($referer_ok != 1) { $errmesg ="Sorry! You can't run this script from your server. Please use your own script.
$errmesg__END_OF_ERROR__ exit; } ################################################################## sub send_blocked_notice { $theMail = "To: $RECIPIENT\n"; $theMail .= "From: blocked\@YOUR-DOMAIN-HERE.com\n"; $theMail .= "Subject: \@Blocked IP deflected\n\n"; $theMail .= "$ENV{'REMOTE_ADDR'} ($ENV{'HTTP_X_FORWARDED_FOR'}) was denied access to sendmail!\n"; $theMail .= "User-Agent: $ENV{'HTTP_USER_AGENT'}\n"; $theMail .= "Http-Referer: $ENV{'HTTP_REFERER'}\n"; open(MZT,"|$MAIL_PROGRAM -t") || die "Unable to send mail: $^E"; print MZT $theMail; close(MZT); }