#!/usr/bin/perl
# Enter the location of sendmail.
$mailprogram = "/usr/sbin/sendmail -t";
@required = ('email','name','country');
$youremail = "somebody\@your_address.co.uk.";
$emailmessage = <<'COMPLETEWRITING';
Thank you for your enquiry.
I will answer your query as fully and as soon as possible.
Mike
your company
COMPLETEWRITING
# Put the posted data into variables
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# Check for all required fields
foreach $check(@required) {
unless ($FORM{$check}) {
print "Content-type: text/html\n\n";
print "<html><head><title>Missing Information</title></head>\n";
print "<body><h1>Missing Information</h1><br>\n";
print "I'm sorry, but it would appear that you've forgotten to\n";
print "fill out the $check field. Please click\n";
print "back and try again.\n";
print "</body></html>\n";
exit;
}
}
# Check the senders email
if ($FORM{'email'}) {
unless ($FORM{'email'} =~ /\w+@\w+.\w+/) {
print "Content-type: text/html\n\n";
print "<html><head><title>Bad E-mail</title></head>\n";
print "<body><h1>Bad E-mail</h1><br>The e-mail address that you've\n";
print "entered, $FORM{'email'}, is invalid. Please click back and\n";
print "try again.\n";
exit;
}
}
open (MAIL,"|$mailprogram");
print MAIL "To: $youremail\n";
print MAIL "From: $FORM{'email'}\n";
print MAIL "Subject: $FORM{'subject'}\n";
print MAIL "Hello. The following information has been submitted:\n\n";
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
unless ($name eq "response" || $name eq "email" || $name eq "subject") {
print MAIL "$name: $value\n";
}
}
close MAIL;
open (MAIL, "|$mailprogram") || &cgidie ("Can't open $mailprog!\n");
print MAIL "To: $FORM{'email'}\n";
print MAIL "From: $youremail\n";
print MAIL "Subject: $FORM{'subject'} -- Autoresponse\n";
print MAIL "$emailmessage\n\n";
close MAIL;
print "Content-type: text/html\n\n";
print "<html><head><title>Thank you!</title></head>\n";
print "<body><h1>Thank you!</h1><br>Thanks for your input! \n";
print "You should receive an autoresponse shortly.<p>\n";
print "Please click back.\n";