#!/usr/bin/perl -w ################################################################################ # # FeedMe v0.11 # # This script is among the easiest to configure. Upload it to your 'nix # server, then chmod it to 755. Then make sure the path to sendmail is correct # for your server, and you're in business. # # v0.11: added lousy form validation. # ##################################### faker@faketp.com # set your path to the sendmail program on your server $sendmail = "/usr/sbin/sendmail"; # Recipient address (e.g. "me\@inter.net") $recipient="me\@my.domain"; ############### OPTIONAL CONFIGURATION #################### # Variables set here take precedence over the values that could be # sent in through the form request # Default sender address (e.g. "you\@inter.net") $def_from=""; # Redirect page (this takes precedence over a "redirect" value sent from the form) $redirect="/"; # Prefix for subject line (set to "feedback:" to receive mail with subjects like # "feedback: user input here") $sub_prefix="Feedback: "; # Can this script check whether you have a stylesheet named "style.css" in this # directory and if one is not there, create it? (to confirm enter "yes") $styler = "yes"; # If you want to specify the location of your own stylesheet, do so here: $style_loc = ""; # You can have a javascript alert tell the user the message is completed. If you # want to do this, set your confirmation message here: $jsalert="Thanks for the input."; # Do you want to give users an option to select between HTML and text mail input? # Set "yes" to allow, otherwise default of text format will be used. $formats="yes"; # Do you want to eliminate the HTML header/footer content? This is useful if plan # to include this script with SSI into a .shtml page to generate a form and process # it, but when you don't want to use any footer or header. Set "yes" if so. $head_foot="yes"; # By default, the script tries to process mail with run with no query string. If no # message was submitted, it will give an informative error message. This works best # when the script is called from an external web form rather than its internal form. # If you prefer to use the internal form, such as in an SSI, it is handy to change the # default actions so that with no query string, the script draws a form. To do so, # set the $prefer_form variable to "yes"....when it works! ######################################################### # # THAT'S IT. POWERUSERS ONLY BELOW THIS POINT # ######################################################### &parse; &vars; unless ($recipient) { &ezerror("Your message cannot be sent without a ''to'' address included in the mail script.")} if ($action eq 'w') {&write} elsif ($action eq 'fmake') {&fmake} elsif ($action eq 'sendMessage') {&sendMessage} else {&write} # comment out either the &write line (for auto-form creation) or the # else {&sendMessage} # &sendMessage line (when linking other form to it) to select a default action ############################## sub head { # Write the header used on each admin page print "Content-type: text/html\n\n"; if ($head_foot eq "yes") { print <$prog | $prog_desc \n \n \n \n \n \n
\n Send a message to $recipient\n

\n\n EOF } } ############################## sub foot { # Write the footer used on each admin page if ($head_foot eq "yes") { print <
\n $prog from faketp.com.\n
\n EOF } exit; } ############################### sub write { &head; print <
Your Name:
Your E-mail Address:

$format_select
TOEOF &foot; } ############################## sub vars { # Set standard variables $prog = "FeedMe v0.11"; $prog_desc = "An easy way to use mail forms without facilitating spam | by FakeTP.com"; $script=$ENV{SCRIPT_NAME}; if ($styler eq "yes") {&fmake} unless ($style_loc) { $style_loc = "style.css" } unless ($redirect) { $redirect=$formdata{'redirect'} } if ($redirect eq "") {$redirect = "/" } unless ($sub_prefix) { $sub_prefix=$formdata{'sub_prefix'} } if ($formats eq "yes") { $format_select = "Mail format:\n" }; $action=$formdata{'action'}; &Dates; sub Dates { # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $y2k = $year + 1900; @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); @months = qw(January February March April May June July August September October November December); @moXX = qw(1 2 3 4 5 6 7 8 9 10 11 12); $date = $mday; $date = "$mday $months[$mon] $y2k" || &ezerror("sub DefineVars"); } } ############################### sub parse { if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); if ($ENV{'QUERY_STRING'}) { @getpairs =split(/&/, $ENV{'QUERY_STRING'}); push(@pairs,@getpairs); } } else { print "Content-type: text/html\n\n"; print "

Use Post or Get"; } foreach $pair (@pairs) { ($key, $value) = split (/=/, $pair); $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~s///g; if ($formdata{$key}) { $formdata{$key} .= ", $value"; } else { $formdata{$key} = $value; } } } ############################## sub sendMessage { $sender=$formdata{'sender'}; $name="$formdata{'name'}"; $subject=$formdata{'subject'}; $body=$formdata{'body'}; $mail_type=$formdata{'mail_type'}; unless ($body) { &ezerror("This script cannot proceed.

If you just submitted a form, please go back and fill out its message area.

If you are trying to access the form, then try this: ")} open (MAIL,"|$sendmail -t") || &ezerror("Can't open sendmail"); print MAIL < To: $recipient Subject: $sub_prefix $subject MESSAGE if ($mail_type eq "html") { print MAIL < var jsalert="$jsalert"; if (jsalert) {alert(jsalert)} window.location='$redirect' OUT } ############################## sub fmake { $fcheck = "./style.css"; $fdef = "\n \n p { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} \n .copy { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; text-align:center} \n td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt} \n pre { font-family: \"Courier New\", Courier, mono; font-size: 10pt} \n .subhead2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12pt} \n h2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18pt; font-weight: bold } \n code { font-family: \"Courier New\", Courier, mono; font-size: 10pt} \n th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt ; font-weight: bold} \n sup { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt} \n .bodyItalic { font-family: Verdana, Arial, Helvetica, sans-serif; font-style: italic; font-size: 10pt} \n h1 { font: bold normal 24pt Verdana, Arial, Helvetica, sans-serif} \n h3 { font: bold normal 14pt Verdana, Arial, Helvetica, sans-serif} \n h4 { font: bold normal 12pt Verdana, Arial, Helvetica, sans-serif} \n li { font: 10pt Verdana, Arial, Helvetica, sans-serif} \n ul { font: 10pt Verdana, Arial, Helvetica, sans-serif} \n .buttons { font: bold normal 9pt Verdana, Arial, Helvetica, sans-serif} \n h5 { font: bold normal 10pt Verdana, Arial, Helvetica, sans-serif} \n h6 { font: bold normal 9pt Verdana, Arial, Helvetica, sans-serif} \n body { background-color: #FFFFFF} \n a:link {color:#0000ff} \n a:visited {color: #004080} \n a:active {color:#} \n a:hover {color:#808080; text-decoration: none} \n \n "; &fmake_it; sub fmake_it { unless (-e "$fcheck") { open (FILE, ">$fcheck") || &ezerror("k65"); print FILE "$fdef" || &ezerror("ne33"); close (FILE); } } } ############################## sub ezerror { print "Content-type: text/html\n\n"; print "
$script error:
$_[0]
\n"; exit; }