#!/usr/bin/perl
# File name: form_handler.cgi
# send e-mail containing user's input to a form
# remember to put your handle on the front of this file name
&setup;
&main;
sub main
{
# here we check for malicious hackery
$bad_input = "";
foreach $item (values %in)
{
if ($item =~ /[<>\*`\|]/)
{
$bad_input = "yes";
}
}
if ($bad_input eq "yes")
{
&html_header;
print "
Please use only standard characters in this input.
";
&html_footer;
}
else
{
# here we ccheck the input for problems
if ($in{'name'} eq "")
{
&html_header;
print "
\n";
&html_footer;
}
else
{
&send_email;
&show_message;
}
}
}
sub setup
{
print "Content-type: text/html\r\n";
print "\r\n";
require '../../../../cgi-bin/cgi-lib.pl'; # this links to cgi-bin.pl on David Mc's account
&ReadParse;
$cgi_name = "form_handler.cgi"; # change this to the file name based on your handle
$my_email = $in{'my_email'};
$start_day = (localtime) [3];
$start_month = (localtime) [4] + 1;
$start_year = (localtime) [5] + 1900;
$received_date = "$start_month/$start_day/$start_year";
}
sub send_email
{
print "\n";
$to = $in{'my_email'};
open (MAIL, "| /usr/sbin/sendmail -t") || die "error: can't start mail program";
print MAIL "To: $to \n";
print MAIL "From: Texas Tours <$my_email> \n";
print MAIL "Subject: Request for tour received $received_date \n\n";
print MAIL "We have just received this tour request:\n\n";
print MAIL "Name: $in{'name'} \n";
print MAIL "E-mail: $in{'email'} \n";
print MAIL "Group number: $in{'tour_group'} \n";
print MAIL "Start date: $in{'start_date'} \n";
print MAIL "End date: $in{'end_date'} \n";
close MAIL;
}
sub show_message
{
# show student okay web page
&html_header;
print " \n";
print "
Okay, a potential customer filled out the questionnaire on $received_date.