#!/usr/bin/perl -wT
#
# mail cgi

#### modules (these don't need changing)
#
# be strict, define all variables
use strict;

# use CGI.pm for parsing form data and printing headers/footers
use CGI;

# redirect errors to the browser window
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

# create an instance of CGI.pm:
my($cgi) = CGI->new;

# CONFIGURE: change this to the proper location of sendmail on your system:
my($mailprog) = '/usr/sbin/sendmail';

# Set the path, so taint mode won't complain. This should be the path
# that sendmail lives in!  (If you're using /usr/lib/sendmail, then
# the path had better be /usr/lib here.)
$ENV{PATH} = "/usr/sbin";

# CONFIGURE: change this to the e-mail address you want to receive the 
# mailed form data
my($recipient) = 'tgarner@pdsolutions.ca';

# CONFIGURE: change this to your URL:
my($homepage) = "http://www.pdsolutions.ca/";

# CONFIGURE: change this to the subject you want the e-mail to have
# WARNING: Do NOT Let the form specify the subject line, or your
# program can be hijacked by spammers!!!
my($subj) = "PD Solutions Order Form";

# everything below this shouldn't need changing, except possibly the
# "thank you" page at the end.

# Print out a content-type header
print $cgi->header;

# CGI.pm automatically parses the data, and you can retrieve it using
#    $cgi->param("fieldname")

# Now send mail to $recipient
open (MAIL, "|$mailprog -t") || &dienice("Can't open $mailprog!\n");
print MAIL "To: $recipient\n";
print MAIL "From: $recipient\n";
print MAIL "Subject: $subj\n\n";

# print all of the form fields:
foreach my $i ($cgi->param()) {
    print MAIL $i . ": " . $cgi->param($i) . "\n";
}
print MAIL "\n\n";

# print some extra info:
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "HTTP From: $ENV{'HTTP_FROM'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);

# CGI.pm prints the HTML header
print $cgi->start_html(-title=>"Thank You", 
       -bgcolor=>"#ffffff",
       -text=>"#000000");

# CONFIGURE:
# Print a thank-you page - you can customize this however you wish.
# Be sure to use proper HTML, and escape any $-signs or @-signs with a 
# backslash, e.g.:  \$25.00, nullbox\@cgi101.com

print <<EndHTML;
<center>
<H3>PD Solutions</H3>
</center><P>
<H3>Thank you for your order - We will contact you shortly with confirmation!</H3>
<P>

Best Regards<br>
PD Solutions <P>
Return To Our <a href="$homepage"><B>Home Page</B></a></H4>
</p>
EndHTML

# CGI.pm prints the HTML footer
print $cgi->end_html;

# error handler
sub dienice {
    my($msg) = @_;
    print $cgi->start_html(-title=>"Error");
    print qq(<h2>Error</h2>\n);
    print $msg;
    print $cgi->end_html;
    exit;
}

# the end.