#!/usr/bin/perl # Mailscript v1.25 # This is a basic script used to send an email from a web based interface. # Original author unknown - modified by Hans Nurge 8/1/00 # .1 modified to send a tankyou email back to the visitor. # .2 10/20/00 Modified to send HTML formatted email # .25 checks for conf_subject and if not present uses subject for backward compatability, # also checks for subject and if not present puts in default. # --------- Required Variables: ------ # redirect - html page to direct to upon submission(thank you page) # recipient - primary recipiant # client_email - email of sender (return address and adress for 'thank you') # --------- Optional Variables -------- # subject - Message subject (primary email) # conf_subject - Message subject ('thank you' email) use Socket; my(%FORM); $mailprog = '/usr/sbin/sendmail'; $domain = "duncanvilleisd.org"; $domain1 = "http://www3." . $domain; $domain2 = "http://www." . $domain; if ($ENV{'HTTP_REFERER'} !~ /$domain1/is && $ENV{'HTTP_REFERER'} !~ /$domain2/is ) { print qq~Content-type: text/html\n\n
Please fill in all required entries.

Return to Form ~; exit; } # Parse form input &parse_form; &send_mail; print "Location: $FORM{'redirect'}\n\n"; #---------------Main Program--------------------------------------- sub send_mail { # Open The Mail Program open(MAIL,"|$mailprog -t"); #--Send Mail to Merchant to notify them of sale print MAIL "To: $FORM{'recipient'}\n"; print MAIL "From: $FORM{'client_email'}\n"; # Check for Message Subject $FORM{'subject'} = "E-mail responce from CGI form at $ENV{HTTP_REFERER}" if $FORM{'subject'} eq ''; print MAIL "Subject: $FORM{'subject'}\n"; print MAIL "Content-Type: text/html; charset=us-ascii\n\n"; # for non HTML Email print MAIL "\n"; # for HTML Email print MAIL "\n"; print MAIL "\n"; print MAIL "\n"; } } print MAIL "

\n"; print MAIL "

The following form was submitted at
$ENV{HTTP_REFERER}

\n"; foreach $key (keys %FORM) { if ($key ne 'client_email' && $key ne 'subject' && $key ne 'title' && $key ne 'recipient' && $key ne 'redirect' && $key ne 'conf_subject' && $key ne 'Submit' && $key ne 'SUBMIT' && $key ne 'submit') { print MAIL "

$key $FORM{$key}
\n"; print MAIL "\n"; #Send Thankyou Email if ($FORM{'Email Address'} ne '') { open(MAIL,"|$mailprog -t"); print MAIL "To: $FORM{'Email Address'}\n"; print MAIL "From: $FORM{'recipient'}\n"; # Check for Conformation Message Subject $FORM{'conf_subject'} = $FORM{'subject'} if $FORM{'conf_subject'} eq ''; print MAIL "Subject: $FORM{'conf_subject'}\n\n"; print MAIL "---------------------------------------------------------------------------\n\n"; print MAIL "\n"; print MAIL "Thank You for your recent interest in our products, your email has been received and shall be answered shortly.\n\n "; } } # parse form input sub parse_form { my(@pairs); if ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @pairs = split(/&/, $buffer); } foreach $pair (@pairs) { my($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ 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; # If they try to include server side includes, erase them, so they # arent a security risk if the html gets returned. $value =~ s///g; if ($name eq 'bgcolor' || $name eq 'background' || $name eq 'link_color' || $name eq 'vlink_color' || $name eq 'text_color' || $name eq 'alink_color' || $name eq 'title' || $name eq 'sort' || $name eq 'print_config' || $name eq 'return_link_title' || $name eq 'return_link_url' && ($value)) { $CONFIG{$name} = $value; } elsif ($name eq 'required') { @required = split(/,/,$value); } elsif ($name eq 'exclude') { @exclude = split(/,/,$value); } else { if ($FORM{$name} && ($value)) { $FORM{$name} = "$FORM{$name}, $value"; } elsif ($value) { $FORM{$name} = $value; } } } } exit (0);