##
require "my-cgi-includes.pl";
my %input = %{getforminput()};
####
sub getforminput {
my %in;
my $buffer; # Because this is now a subroutine that can get
# called from various places, we must be careful
# not to tromp on the script's own variables.
if ($ENV{'REQUEST_METHOD'} eq "GET") {$buffer = $ENV{'QUERY_STRING'};}
elsif ($ENV{'REQUENT_METHOD'} eq "POST") {
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
} else {
return undef; # If $ENV{REQUEST_METHOD} is not set, maybe there's no input.
# In that case the script will probably print a blank form.
}
# I'm not sure what your assigning from $buffer to $bufferb was
# intended to accomplish, but I think it just creates an extra
# variable. Skip it, and go straight to the split:
my @forminputs = split(/&/, $buffer);
foreach $forminput (@forminputs)
{
my ($name, $value) = split(/=/, $forminput);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-f0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Some of that stuff cgi could do for you, possibly better, but
# for now we'll move on...
$in{$name} = $value;
# Good. You did right to put the input in a hash. Not
# only is it convenient to access that way, but it is
# also all together in one nice container that can be
# easily passed around, and there is no risk of tromping
# on other variables (as there would be with $$name=$value
# and similar hacks).
}
return \%in;
}
####
print "Content-type: text/html\n\n";
#mail sent to admin
open (LMAIL, "|usr/sbin/sendmail -t");
print LMAIL("To: $in{myEmail}\n");
print LMAIL ("From: $in{Email}\n");
print LMAIL ("Subject: $in{Form}\n");
print LMAIL ("--------------------\n\n");
print LMAIL("$in{Message}\n\n");
#mail sent to user
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL<##
my %input=%{getforminput()};
my $validto = "jonadab\@bright.net,jonadab_homeip_net\@yahoo.co.uk";
if ($validto !~ $input{myEmail}) {
$errors .= "The To: address you selected was not one of the available choices. Please pick an option from the dropdown list. \n"; }
if ($input{Email} !~ /^[^@]+[@][^@]+$/) {
$errors .= "The From: address you entered does not appear to be valid. Please enter a real email address. \n"; }
if (not $input{Subject}) {
$errors .= "You left the subject blank. Please fill in a short description of what your message is about. \n"; }
if (not $input{Message}) {
$errors .= "You left the message itself blank. Surely you had something to say? \n"; }
if ($errors) {
print "Content-type: text/html
\n\nError(s) encountered \n
\nOne or more errors were encountered when trying to send your message.
Please hit your browser's back button and correct the following issues:\n
$errors
\n\n\n";
exit 0; # Update: If there were errors, we don't want to send the message.
}
####
sub sendmail {
my ($to, $from, $subject, $body) = @_;
open (LMAIL, "|usr/sbin/sendmail -t");
print LMAIL("To: $to\n");
print LMAIL ("From: $from\n");
print LMAIL ("Subject: $subject\n");
print LMAIL ("--------------------\n\n");
print LMAIL ("$body\n\n");
print LMAIL ("-- \nSent from $ENV{REMOTE_ADDR} using $0 on $ENV{HOSTNAME}\n");
close LMAIL;
}
####
# mail sent to admin
sendmail($input{myEmail}, $input{Email}, $input{Subject}, $input{Message});
# mail sent to user
sendmail($input{Email}, $input{myEmail}, "Re: ".$input{Subject}, "Thanks for your email! \n\n");
####
#submit screen
print ("$in{Form}");
print ("");
print ("Thanks for your email.");
print ("##
sub H{$_=shift;while($_){$c=0;while(s/^2//){$c++;}s/^4//;$
v.=(' ','|','_',"\n",'\\','/')[$c]}$v}sub A{$_=shift;while
($_){$d=hex chop;for(1..4){$pl.=($d%2)?4:2;$d>>=1}}$pl}$H=
"16f6da116f6db14b4b0906c4f324";print H(A($H)) # -- jonadab