email.cgi

 


#!/usr/bin/perl

print "Content-type:text/html\n\n";

### Put all email addresses in array
open (EMAILLIST, "</news/addresses.txt") || &ErrorMessage;
@addresses = <EMAILLIST>;
close (EMAILLIST);




@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs)
{
    ($key, $value) = split (/=/, $pair);
    $key =~ tr/+/ /;
    $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~s/<!--(.|\n)*-->//g;

    if ($formdata{$key})
    {
        $formdata{$key} .= ", $value";
    }
    else
    {
        $formdata{$key} = $value;
    }
}


$from = $formdata{'from'};
$subject = $formdata{'subject'};
$contents = $formdata{'contents'};




$n=1;

open (ADDRESSES, "</news/addresses.txt") || &ErrorMessage;
@eaddresses = <ADDRESSES>;
close (ADDRESSES);

print "<blockquote>Sending email message to...\n</blockquote>"; 

foreach $address (@eaddresses) 
{
   print "<blockquote>$address\n</blockquote>"; 

   ###   print "<blockquote>Subject: $subject\n</blockquote>"; 
   ###   print "<blockquote>Contents: $contents\n</blockquote>";  

   $n++;

   open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;

   print MAIL "To: $address \nFrom: $from\n";
   print MAIL "Subject: $subject\n";
   print MAIL "$contents\n";

   close (MAIL);

}



sub ErrorMessage {
 print "Content-type: text/html\n\n";
 print "The server can't the file. It either doesn't exist or the permissions are wrong. \n";
 exit;
}