[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-WebCGI] Expanding the email program



I'm very much so a newbie when it comes to perl, so please bear with me here. 
 
After a small amount of work, I've created a small email program for my own 
personal uses.  For now it works okay, but it's now very versitile.  Right 
now it only sends 3 fields, name, email address, and a message.  What I want 
to do though it make it so the mail program can send information that is 
undefined by program, ie.  I want to be able to do something like add extra 
fields to the page the message is sent from without having to add the extra 
varables to the email program, only it just don't know how to go about doing 
that.  I hope I've explained myself well enough.  Thanks-Nate

<-------------------start program-------------------------------->
#!/usr/bin/perl


$MailProgram = '/usr/sbin/sendmail';
&ReadParse;
$Name = $in{'name'};
$Email = $in{'email'};
$Message = $in{'message'};
$YourEmail = $in{'youremail'};
$Subject = $in{'subject'};
$ThankPage = $in{'thankpage'};
$ErrorPage = "http://loup_garou21.tripod.com/no.html";
&CheckEmailAddressFormat;
&CheckFields;
&SendSubmission;
print "Location: $ThankPage\n\n";
exit;

sub ReadParse { local (*in) = @_ if @_; 
local ($i, $key, $val); if ( $ENV{'REQUEST_METHOD'} eq "GET" ) 
{$in = $ENV{'QUERY_STRING'};} 
elsif ($ENV{'REQUEST_METHOD'} eq "POST") 
{read(STDIN,$in,$ENV{'CONTENT_LENGTH'});} 
else { 
$in = ( grep( !/^-/, @ARGV )) [0];
$in =~ s/\\&/&/g; } @in = split(/&/,$in);
foreach $i (0 .. $#in) { 
$in[$i] =~ s/\+/ /g; 
($key, $val) = split(/=/,$in[$i],2); 
$key =~ s/%(..)/pack("c",hex($1))/ge; 
$val =~ s/%(..)/pack("c",hex($1))/ge; 
$in{$key} .= "\0" if (defined($in{$key})); 
$in{$key} .= $val; } return length($in); }

sub CheckEmailAddressFormat {
if (index($Email, "@") < 1)  {&DoEmailError;}
if (index($Email, ".") < 1)  {&DoEmailError;}
if (index($Email, " ") > -1) {&DoEmailError;}
}

sub CheckFields {
if (!$Name || $Name eq ' ') {&DoEmailError;}
if (!$Email || $Email eq ' ') {&DoEmailError;}
if (!$Message || $Message eq ' ') {&DoEmailError;}
}

sub SendSubmission {
open (MAIL,"|$MailProgram -t");
print MAIL "To: $YourEmail\n";
print MAIL "From: $Email\n";
print MAIL "Subject: $Subject\n";
print MAIL "From: $Name\n";
print MAIL "Email: $Email\n\n";
print MAIL "Message:\n\n";
print MAIL "$Message\n\n";
close (MAIL);
}

sub DoEmailError {
print "Location: $ErrorPage\n\n";
exit;

}

exit;

<-------------------End program--------------------->

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org