North323 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); ######################## Program Header ############################## +########### ## ## Copyright (C) 2004 Poetic Pollution ## Script Name: BareBonesMailer ## Version: 0.2.4 ## URL: http://poeticpollution.net/scripts/BareBonesMailer/ ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License ## as published by the Free Software Foundation; either version 2 ## of the License, or (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## Please read the full GNU GPL: http://www.gnu.org/copyleft/gpl.html ## ###################################################################### +########### ######################## User Defined Variables ###################### +## ## Edit as needed... # Path to sendmail $mailProg = "/usr/sbin/sendmail -t"; # Your email address and be sure to leave the \ in front # of the @ or else you'll get errors.. ;) $toEmail = "you\@yourdomain.com"; # Domains that are able to use the mailer script # Enclose in quotes and seperate each with a comma @valid_referrers = ("yourdomain.com","yourotherdomain.com"); # Redirect them to this URL: # This should be a pre-existing file with a thank you # message or something similar.. $redirectURL = "http://www.yourdomain.com/thanks.html"; # Your time zone difference from GMT $offSet = "-7"; # Military time 0 = off 1 = on $milTime = 0; ######################## Engage Mailer ######################## ## Don't Edit Below Here Unless You Know How... $valid_http_referrer = 0; foreach(@valid_referrers) { if($ENV{'HTTP_REFERER'} =~ /^https?:\/\/(www\.)?$_/i) { $valid_http_referrer = 1; last; } } unless($valid_http_referrer) { &headerFooter; print qq|You are coming from the wrong page. Please go back and tr +y again..\n|; print @footer; exit; } $fromName = param('nameField'); $fromEmail = param('emailField'); $formContents = param('formField'); $formSubject = param('Subject'); unless($fromName) { &headerFooter; print qq|The <b>Name</b> field is required. Please go back and try + again..\n|; print @footer; exit; } unless(($fromEmail) && ($fromEmail =~ /.*\@.*/)) { &headerFooter; print qq|The <b>Email</b> field is required. Please go back and tr +y again..\n|; print @footer; exit; } unless($formContents) { &headerFooter; print qq|You must include a message of some sorts. Please go back +and try again..\n|; print @footer; exit; } @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); @time = gmtime(time + (3600 * $offSet)); $newMinSec = sprintf("%02d:%02d",$time[1],$time[0]); $newDay = sprintf("%02d",$time[3]); $years = $time[5] + 1900; if ($milTime) { $hours = sprintf("%02d",$time[2]); } else { if ($time[2] < 12) { if ($time[2] == 0) { $hours = 12; } else { $h +ours = $time[2]; } $amPm = " AM"; } else { if ($time[2] > 12) { $hours = $time[2] - 12; } else { $hour +s = $time[2]; } $amPm = " PM"; } } $dateFormat = "$newDay/$months[$time[4]]/$years at $hours:$newMinSec$a +mPm"; $remoteAddress = $ENV{'REMOTE_ADDR'}; $remoteHost = $ENV{'REMOTE_HOST'}; @subnetNumbers = split (/\./, $remoteAddress); $packedAddress = pack ("C4", @subnetNumbers); ($remoteHost) = gethostbyaddr ($packedAddress, 2); open(MAIL, "|$mailProg") || die "Unable to open Mail Program."; print MAIL "To: $toEmail\n"; print MAIL "From: $fromEmail\n"; print MAIL "Subject: $formSubject\n"; print MAIL "Date: $dateFormat.\n\n"; print MAIL "Name: $fromName <$fromEmail>\n"; print MAIL "$remoteHost / $remoteAddress\n"; print MAIL "Browser: $ENV{'HTTP_USER_AGENT'}\n"; print MAIL "Subject: $formSubject\n\n"; print MAIL "$formContents\n"; close(MAIL); print "Location: $redirectURL\n\n"; exit; sub headerFooter { # ------------------------------------------------ open (FILE, "mailer-template.html") || die "Unable to open the Mailer +Template for reading.."; @HTMLFile = <FILE>; close(FILE); for ($a = 0; $a < @HTMLFile; $a++) { if ($HTMLFile[$a] =~ /<!-- mailer + output will be here -->/) { $foundIt = 1; last; } } unless($foundIt) { die "HTML comments not found in the Mailer Template +.."; } for ($i = 0; $i < $a; $i++) { push(@header, $HTMLFile[$i]); } for ($i = $a; $i < @HTMLFile; $i++) { push(@footer, $HTMLFile[$i]); } print "Content-type: text/html\n\n"; print @header; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing Headers in Perl
by Corion (Patriarch) on Nov 11, 2007 at 20:34 UTC | |
by North323 (Initiate) on Nov 11, 2007 at 20:54 UTC | |
by Corion (Patriarch) on Nov 11, 2007 at 21:25 UTC | |
by North323 (Initiate) on Nov 11, 2007 at 21:37 UTC | |
by Corion (Patriarch) on Nov 11, 2007 at 21:44 UTC | |
| |
|
Re: Removing Headers in Perl
by GrandFather (Saint) on Nov 11, 2007 at 20:53 UTC | |
by North323 (Initiate) on Nov 11, 2007 at 21:09 UTC | |
|
Re: Removing Headers in Perl
by LassiLantar (Monk) on Nov 11, 2007 at 19:34 UTC | |
by North323 (Initiate) on Nov 11, 2007 at 19:36 UTC | |
|
Re: Removing Headers in Perl
by narainhere (Monk) on Nov 12, 2007 at 07:25 UTC |