
Perl CGI Script EMails nothing
Hi I have been just starting to learn perl and my first script just don't
work.
It debugs ok and it sends the mail ok. Unfortunately it does not send the
main message and i cannot find a syntax error in the script.
I know it's bad practice to just post a load of code to a ng however if
anyone can see a bug screaming out then please mail me.
I checked the content length and the script definately receives some text
but then loses it somewhere
Thanks in advance
Alex
#! /bin/perl
#This is the sub main part of the script
%data_in = &Parse_String();
foreach $key (sort keys(%data_in))
{
$mail .="$key:\n";
foreach (split (" : ",$data_in{$key}))
{
$mail .= "$_\n\n";
}
}
&Email_Str ($mail);
&ResponsePage;
sub Parse_String
{
#Check how the data was sent : POST or GET
if ($ENV{'REQUEST_METHOD'} eq "POST")
{
read(STDIN,$Parse_String,$ENV{'CONTENT_LENGTH'});
}
else
{
$Parse_String=$ENV{'QUERY_STRING'};
}
#NOW TAKE THE STRING AND CONVERT + TO SPC
$Parse_String=~ s/\+/ /g;
#CREATE ASSOCIATIVE ARRAY AND ADD VALUES
{
($name,$value)=split(/=/,$Pair_Values);
$name= ~s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C",hex($1))/ge;
$value= ~s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C",hex($1))/ge;
#IF MULTIPLE VALUES WITH SAME NAME THEN DEAL WITH IT
if (defined($Parse_String{$name}))
{
$Parse_String{$name} .= " : " . $value;
}
else
{
$Parse_String {$name}=$value;
}
}
return %Parse_String;
Quote:
}
#Write Confirmation Page
#Temporary Response Page
sub ResponsePage {
local (%ResponsePage);
print "Content-type: text/html\n\n";
print "<html><Title>Form Posted</Title>";
print "<Body><p><p><p><p><H1>Thankyou For Filling this Form in</H1>";
Version</a>";
print "</Body> </html>";
return %ResponsePage;
Quote:
}
#send Email
sub Email_Str
{
open (MAIL, "|/usr/lib/sendmail -t") ||
die "Context-type: text/text\n\nCan't open /usr/lib/sendmail !\n";
print MAIL "Subject: Mail FeedBack\n";
print MAIL "$message \n\n";
return close(MAIL)
Quote:
}
--
The Wizzard