#!/usr/local/bin/perl
## Mail Form Handler (mail_form.pl) Copyright 1998-2002 by Tim Stevenson, tstevens\@employees.org
## Generic HTML form-processing CGI script
## Version 3.2w -- Modified April 2002
## Version 3.1w -- Modified December 2000
## Version 3.1 -- Modified July 2000
## Version 3.0 -- Modified July 1999
## Version 2.0 -- Modified January 1998
## Version 1.0 -- Modified March 1997
## Based on mailit.pl by ccoluzzi\@cisco.com; ReadParse subroutine by Steven E. Brenner
$version = "3.2w";
# Supported "special" form fields and their "required" versions are contained
# in the array \@specials (except the special case for "Full Name", which sometimes
# should be displayed).
@special_fields = ("Recipient Address", "Cc Address", "Auto Cc", "Email Subject Line", "Background Color", "Link Color", "ActiveLink Color", "VisitedLink Color", "Text Color", "Toggle Graphics", "Required Graphic", "Graphic", "Magic Word", "Response Page Title", "Greeting", "Return URL", "Return Link Text", "Show Blanks", "Show Results");
foreach (@special_fields) {
push (@specials, $_);
$_ =~ s/$/*/;
push (@specials, $_);
}
# Get info about script and server
$script_filename = $script_path = $ENV{SCRIPT_NAME};
$script_filename =~ s#.*/([^/]+)$#\1#;
$script_path =~ s#^//#/#;
$server = $ENV{SERVER_NAME};
$server =~ s#/##g;
# Default Variables
$ADDRESS = $DEF_ADDRESS = "nobody\@example.com";
$EMAIL_ADDRESS = $DEF_EMAIL_ADDRESS = $RETURN_ADDRESS = "nobody";
$COPY_ADDRESS = $DEF_COPY_ADDRESS = "";
$AUTO_COPY = $DEF_AUTO_COPY = "No";
$FULL_NAME = $DEF_FULL_NAME = "exclude;Mail Form Handler";
$SUBJECT = $DEF_SUBJECT = "Form Submission";
$BKGD_COLOR = $DEF_BKGD_COLOR = "white";
$LINK_COLOR = $DEF_LINK_COLOR = ""; #unspecified
$ALINK_COLOR = $DEF_ALINK_COLOR = ""; #unspecified
$VLINK_COLOR = $DEF_VLINK_COLOR = ""; #unspecified
$TEXT_COLOR = $DEF_TEXT_COLOR = "black";
$REQUIRED_URL = $DEF_REQUIRED_URL = "http://www.example.com/imglib/some.gif";
$TOGGLE_GRAPHICS = $DEF_TOGGLE_GRAPHICS = "On";
$GRAPHIC_URL = $DEF_GRAPHIC_URL = "http://www.example.com/imglib/some_other.gif";
$MAGIC = $DEF_MAGIC = "";
$TITLE = $DEF_TITLE = "Mail Form Handler Response";
$GREETING = $DEF_GREETING = "Thank you for your form submission.";
$RETURN_URL = $DEF_RETURN_URL = "";
$RETURN_LINK_TEXT = $DEF_RETURN_LINK_TEXT = "";
$SHOW_BLANKS = $DEF_SHOW_BLANKS = "No";
$SHOW_RESULTS = $DEF_SHOW_RESULTS = "No";
$bad = 0;
#Print the HTTP header
print "Content-type: text/html", "\n\n";
# ReadParse subroutine handles form input
# If the code in this subroutine isn't working well with your server,
# visit the cgi-lib.pl home page on the web to find a version that works better.
&ReadParse;
# If they don't use "POST", return the help file
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$bad = 1;
$TITLE = "Mail Form Handler Help";
}
if ($ENV{'CONTENT_LENGTH'} == 0) {
$bad = 1;
$TITLE = "Mail Form Handler Help";
}
if ( $bad == 1 ) {
&LocateSendmailRoutine;
&HelpFile;
exit (0);
}
# Check the input names to see which fields are required, which are optional
foreach (keys %in) {
if ($_ =~ /\*$/) {
$required_fields{$_} = "";
}
} #end foreach
## Replace Default values as necessary
# REPLACE DEFAULT BACKGROUND COLOR, IF REQUIRED
if ($in{'Background Color'} ne "") {
$BKGD_COLOR = "bgcolor=\"$in{'Background Color'}\"";
} elsif ($in{'Background Color*'} ne "") {
$BKGD_COLOR = "bgcolor=\"$in{'Background Color*'}\"";
}
# REPLACE DEFAULT LINK COLOR, IF REQUIRED
if ($in{'Link Color'} ne "") {
$LINK_COLOR = "link=\"$in{'Link Color'}\"";
} elsif ($in{'Link Color*'} ne "") {
$LINK_COLOR = "link=\"$in{'Link Color*'}\"";
}
# REPLACE DEFAULT ACTIVE LINK COLOR, IF REQUIRED
if ($in{'ActiveLink Color'} ne "") {
$ALINK_COLOR = "alink=\"$in{'ActiveLink Color'}\"";
} elsif ($in{'ActiveLink Color*'} ne "") {
$ALINK_COLOR = "alink=\"$in{'ActiveLink Color*'}\"";
}
# REPLACE DEFAULT VISITED LINK COLOR, IF REQUIRED
if ($in{'VisitedLink Color'} ne "") {
$VLINK_COLOR = "vlink=\"$in{'VisitedLink Color'}\"";
} elsif ($in{'VisitedLink Color*'} ne "") {
$VLINK_COLOR = "vlink=\"$in{'VisitedLink Color*'}\"";
}
# REPLACE DEFAULT TEXT COLOR, IF REQUIRED
if ($in{'Text Color'} ne "") {
$TEXT_COLOR = "text=\"$in{'Text Color'}\"";
} elsif ($in{'Text Color*'} ne "") {
$TEXT_COLOR = "text=\"$in{'Text Color*'}\"";
}
# REPLACE DEFAULT ADDRESS, IF REQUIRED
$special_field = "Recipient Address";
if ($in{'Recipient Address'} ne "") {
$ADDRESS = "$in{'Recipient Address'}";
&EmailCheck ($ADDRESS);
} elsif ($in{'Recipient Address*'} ne "") {
$ADDRESS = "$in{'Recipient Address*'}";
&EmailCheck ($ADDRESS);
}
# REPLACE DEFAULT EMAIL ADDRESS, IF REQUIRED
$special_field = "Email Address";
if ($in{'Email Address'} ne "") {
$EMAIL_ADDRESS = "$in{'Email Address'}";
&EmailCheck ($EMAIL_ADDRESS);
} elsif ($in{'Email Address*'} ne "") {
$EMAIL_ADDRESS = "$in{'Email Address*'}";
&EmailCheck ($EMAIL_ADDRESS);
}
# REPLACE DEFAULT FULL NAME, IF REQUIRED
$exclude = 0;
if ($in{'Full Name'} ne "") {
$FULL_NAME = "$in{'Full Name'}";
} elsif ($in{'Full Name*'} ne "") {
$FULL_NAME = "$in{'Full Name*'}";
}
if ($FULL_NAME =~ /^exclude;/) {
$FULL_NAME =~ s/^exclude;//;
$exclude = 1;
}
# REPLACE DEFAULT CC ADDRESS, IF REQUIRED
$special_field = "Cc Address";
if ($in{'Cc Address'} ne "") {
$COPY_ADDRESS = "$in{'Cc Address'}";
&EmailCheck ($COPY_ADDRESS);
$COPY_FLAG = 1;
} elsif ($in{'Cc Address*'} ne "") {
$COPY_ADDRESS = "$in{'Cc Address*'}";
&EmailCheck ($COPY_ADDRESS);
$COPY_FLAG = 1;
}
# REPLACE DEFAULT AUTO CC VALUE, IF REQUIRED
if ($in{'Auto Cc'} ne "") {
$AUTO_COPY = "$in{'Auto Cc'}";
} elsif ($in{'Auto Cc*'} ne "") {
$AUTO_COPY = "$in{'Auto Cc*'}";
}
if ($AUTO_COPY eq "Yes") {
if ($COPY_FLAG == 1){
$COPY_ADDRESS .= ", ";
}
$COPY_ADDRESS .= $EMAIL_ADDRESS;
}
# REPLACE DEFAULT SUBJECT, IF REQUIRED
if ($in{'Email Subject Line'} ne "") {
$SUBJECT = "$in{'Email Subject Line'}";
} elsif ($in{'Email Subject Line*'} ne "") {
$SUBJECT = "$in{'Email Subject Line*'}";
}
# REPLACE DEFAULT TITLE, IF REQUIRED
if ($in{'Response Page Title'} ne "") {
$TITLE = "$in{'Response Page Title'}";
} elsif ($in{'Response Page Title*'} ne "") {
$TITLE = "$in{'Response Page Title*'}";
}
# REPLACE DEFAULT TOGGLE GRAPHICS VALUE, IF REQUIRED
if ($in{'Toggle Graphics'} ne "") {
$TOGGLE_GRAPHICS = "$in{'Toggle Graphics'}";
} elsif ($in{'Toggle Graphics*'} ne "") {
$TOGGLE_GRAPHICS = "$in{'Toggle Graphics*'}";
}
# REPLACE DEFAULT GRAPHIC, IF REQUIRED
if ($in{'Graphic'} ne "") {
$GRAPHIC_URL = "$in{'Graphic'}";
} elsif ($in{'Graphic*'} ne "") {
$GRAPHIC_URL = "$in{'Graphic*'}";
}
$GRAPHIC = "";
# REPLACE DEFAULT REQUIRED GRAPHIC, IF REQUIRED
if ($in{'Required Graphic'} ne "") {
$REQUIRED_URL = "$in{'Required Graphic'}";
} elsif ($in{'Required Graphic*'} ne "") {
$REQUIRED_URL = "$in{'Required Graphic*'}";
}
$REQUIRED_GRAPHIC = "
";
# REPLACE DEFAULT MAGIC WORD, IF REQUIRED
if ($in{'Magic Word'} ne "") {
$MAGIC = "$in{'Magic Word'}";
} elsif ($in{'Magic Word*'} ne "") {
$MAGIC = "$in{'Magic Word*'}";
}
# REPLACE DEFAULT SHOW BLANKS, IF REQUIRED
if ($in{'Show Blanks'} ne "") {
$SHOW_BLANKS = "$in{'Show Blanks'}";
} elsif ($in{'Show Blanks*'} ne "") {
$SHOW_BLANKS = "$in{'Show Blanks*'}";
}
$display_blanks = 0;
if ($SHOW_BLANKS eq "No") {
$display_blanks = 1;
}
# REPLACE DEFAULT SHOW RESULTS, IF REQUIRED
if ($in{'Show Results'} ne "") {
$SHOW_RESULTS = "$in{'Show Results'}";
} elsif ($in{'Show Results*'} ne "") {
$SHOW_RESULTS = "$in{'Show Results*'}";
}
# REPLACE DEFAULT RETURN URL, IF REQUIRED
if ($in{'Return URL'} ne "") {
$RETURN_URL = "$in{'Return URL'}";
} elsif ($in{'Return URL*'} ne "") {
$RETURN_URL = "$in{'Return URL*'}";
}
# REPLACE DEFAULT RETURN_LINK_TEXT, IF REQUIRED
if ($in{'Return Link Text'} ne "") {
$RETURN_LINK_TEXT = "$in{'Return Link Text'}";
} elsif ($in{'Return Link Text*'} ne "") {
$RETURN_LINK_TEXT = "$in{'Return Link Text*'}";
}
# REPLACE DEFAULT GREETING, IF REQUIRED
if ($in{'Greeting'} ne "") {
$in{'Greeting'} =~ s/\*/
/g; $GREETING = "$in{'Greeting'}"; } elsif ($in{'Greeting*'} ne "") { $in{'Greeting'} =~ s/\*/
/g; $GREETING = "$in{'Greeting*'}"; } # End default replacements # Make sure required fields have values assigned to them foreach $item (keys (%required_fields)) { $value = $item; chop ($item); if ($in{$value} eq "" || $in{$value} eq $MAGIC) { $TITLE = "Required Fields"; $errormsg .= "
The following field(s) have to be completed before this form can be processed.
Use your browser's Back button to return to the form and complete these field(s) as required. error_message &FooterCode; print "