#!/usr/bin/perl ####################################### # Custom Modified Form Mailer # Based on fmail.pl # All due credit hereby granted to original authors/editors # Created 7/8/02 Last Modified 5/14/03 # Version 3.22 ####################################### use MIME::Lite; MIME::Lite->send('sendmail', "/bin/sendmail"); ###################### # A date for those with no /bin/date # @junk = localtime(time); $date = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$junk[4]]; $junk[5] += 1900; $date .= "-" . $junk[3] . "-" . $junk[5]; $date .= " " . $junk[2] . ":" . $junk[1] . " EST"; $datafile = '/etc/hosts'; ###################### ######################## # A subroutine to die gracefully under html ######################## sub safe_die { print "Content-type: text/plain\n\n"; print @_,"\n"; exit(0); } read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $finddomain = $ENV{'HTTP_REFERER'}; if ($finddomain eq "") { &safe_die("This script requires data via an HTML form. It cannot run independently."); } $finddomain = lc($finddomain); $finddomain =~ s/^http:\/\///; $finddomain =~ s/^www\.//; ($finddomain, $junk) = split(/\//, $finddomain, 2); &check_exists($finddomain); # Split the name-value pairs @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); # Un-Webify plus signs and %-encoding $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ###### Dealing with the recipient and user's real name ###### $salesman = $FORM{user}; @sman[1] = "*** name of user ***"; @sman[2] = "*** name of user ***"; @addy[1] = 'mail@company.com'; @addy[2] = 'testmail@company.com'; #@addy[2] = 'realothermail@company.com'; $rn = $sman[$salesman]; $uname = $addy[$salesman]; ######## Send mail to the Salesman ######## $msg = MIME::Lite->new ( To =>'$uname', Cc =>'ccrecip@company.com', Subject =>$FORM{'subject'}, Type =>'multipart/mixed' ); $msg->attach(Type => 'text/html', Data => qq~

Daily Salesman's Report



Salesman: $rn

Bakery:

Location:


Date:

1st Visit?:


Contacts:
1.
2.
3.


In Office Use (Route to):
   Sales   Acct
   Eng      Mfg  
Topics discussed:


Action Taken:


Action Needed:


Follow Up Needed:


Other:

~); $msg->send; ######## SUB for checking if domain exists ######## sub check_exists { $chkdomain = shift; $found = 0; open(DB, "<$datafile") || &safe_die("Cannot open data file"); while ($lin = ) { chop($lin); ($rest,$tmpdomain) = split(/\s/, $lin, 3); $tmpdomain=~s/\s+//g; if ($tmpdomain eq $chkdomain) { $found = 1; last; } if ($chkdomain eq "https:") { $found = 1; last; } next; } close(DB); if ($found == 0) { &safe_die("$chkdomain Domain does not exist on this server"); } }