#!/usr/bin/perl
$mailprog = '/usr/sbin/sendmail';
$dbfile = '/home/sites/site84/web/cgi-bin/dbfile.txt';

@junk = localtime(time);
$date = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$junk[4]];
$date .= "-" . $junk[3] . "-" . $junk[5];
$date .= " " . $junk[2] . ":" . $junk[1] . " EST";

######################
# Necessary Fields in HTML Form:   (Read the README file for more info)
# recipient = specifies who mail is sent to
# username = specifies the remote users email address for replies
# realname = specifies the remote users real identity
# subject = specifies what you want the subject of your mail to be

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ tr/+/ /;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    
    $FORM{$name} = $value;
}

# clean up the recipient address, to avoid hackers
$whoto = $FORM{'recipient'};
if ($whoto eq "") {
   &safe_die("No Recipient Given!\n");
}

# Open The Mail
open (MAIL, "|$mailprog -t");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $whoto\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL "Below is the information submitted on $date\n";
print MAIL "----------------------------------------------------------------------------------------\n\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
 
    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $name =~ tr/+/ /;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

     $FORM{$name} = $value;

if (($name eq  "recipient")|| 
($name eq  "subject")   || 
($name eq  "Senden")   || 
($name eq  "Send")   || 
($name eq  "thankurl")){

print MAIL "";
}

else {
# Print the MAIL for each name value pair
  print MAIL "$name:  $value\n";
}}
close (MAIL);

#-------This part here --------------------------------------------
# Add to mailing list
if ($FORM{'contestsmaillist'} eq "Yes") {
   
   print "Location: $FORM{'username'}\n\n";
}
#--------^^^^^^^^^---------------This part here--------------------
#-----http://www.tpub.com/cgi-bin/maillist2.cgi?adminaddmail=------
# I need the line above followed by the $FORM{'username'} ---------










# Refer1
if ($FORM{'Refer1a'} eq "") {
   print "Location: $FORM{'thankurl'}\n\n";
}
else {
open (MAIL, "|$mailprog -t");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $FORM{'Refer1a'}\n";
print MAIL "Subject: Hi\n\n";
print MAIL "Just sending this referal e-mail to let you know about a new giveaway on the internet.  It's quick, easy, and who knows you might win.\n";
print MAIL "http://www.tpub.com/newcontest/\n\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
 
    # Un-Webify plus signs and %-encoding

if (($name eq  "recipient")|| 
($name eq  "subject")   || 
($name eq  "Senden")   || 
($name eq  "Send")   || 
($name eq  "thankurl")){

print MAIL "";
}

else {
# Print the MAIL for each name value pair
  print MAIL "";
}}
close (MAIL);
}
# Refer2
if ($FORM{'Refer2a'} eq "") {
   print "Location: $FORM{'thankurl'}\n\n";
}
else {
open (MAIL, "|$mailprog -t");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $FORM{'Refer2a'}\n";
print MAIL "Subject: Hi\n\n";
print MAIL "Just sending this referal e-mail to let you know about a new giveaway on the internet.  It's quick, easy, and who knows you might win.\n";
print MAIL "http://www.tpub.com/newcontest/\n\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
 
    # Un-Webify plus signs and %-encoding

if (($name eq  "recipient")|| 
($name eq  "subject")   || 
($name eq  "Senden")   || 
($name eq  "Send")   || 
($name eq  "thankurl")){

print MAIL "";
}

else {
# Print the MAIL for each name value pair
  print MAIL "";
}}
close (MAIL);
}
# Refer3
if ($FORM{'Refer3a'} eq "") {
   print "Location: $FORM{'thankurl'}\n\n";
}
else {
open (MAIL, "|$mailprog -t");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $FORM{'Refer3a'}\n";
print MAIL "Subject: Hi\n\n";
print MAIL "Just sending this referal e-mail to let you know about a new giveaway on the internet.  It's quick, easy, and who knows you might win.\n";
print MAIL "http://www.tpub.com/newcontest/\n\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
 
    # Un-Webify plus signs and %-encoding

if (($name eq  "recipient")|| 
($name eq  "subject")   || 
($name eq  "Senden")   || 
($name eq  "Send")   || 
($name eq  "thankurl")){

print MAIL "";
}

else {
# Print the MAIL for each name value pair
  print MAIL "";
}}
close (MAIL);
}
# Refer4
if ($FORM{'Refer4a'} eq "") {
   print "Location: $FORM{'thankurl'}\n\n";
}
else {
open (MAIL, "|$mailprog -t");
print MAIL "From: $FORM{'username'}\n";
print MAIL "Reply-To: $FORM{'username'}\n";
print MAIL "To: $FORM{'Refer4a'}\n";
print MAIL "Subject: Hi\n\n";
print MAIL "Just sending this referal e-mail to let you know about a new giveaway on the internet.  It's quick, easy, and who knows you might win.\n";
print MAIL "http://www.tpub.com/newcontest/\n\n";
foreach $pair (@pairs)
{
    ($name, $value) = split(/=/, $pair);
 
    # Un-Webify plus signs and %-encoding

if (($name eq  "recipient")|| 
($name eq  "subject")   || 
($name eq  "Senden")   || 
($name eq  "Send")   || 
($name eq  "thankurl")){

print MAIL "";
}

else {
# Print the MAIL for each name value pair
  print MAIL "";
}}
close (MAIL);
}

{
 print "Location: $FORM{'thankurl'}\n\n";
}
