N
Ning li
Hi,
I am trying to send email to multiple recipients using CGI and form. In
the program, I check for the citycodes in the HTML form using subroutine
"check_citycode()". All the form entries will be emailed to different
recipients depending on the city code entered. The problem is, I always get
the message of "No recipient addresses found in the header", though I know I
put the addresses in the perl script.
Thanks in advance for your help.
Nick Li
The code is as the follow:
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail -i -t';
# Process query string
if( $ENV{'REQUEST_METHOD'} eq "POST" )
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else
{
$buffer = $ENV{"QUERY_STRING"};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$IN{$name} = $value;
}
$my_citycode = check_citycode();
# Print the page header
print "Content-type: text/html\r\n\r\n";
sub mailComment
{
open(MAIL,"|$mailprog");
# The parameter array contains one hash reference. Assign it to a local
variable.
my ($hashReference) = @_;
# Iterate over the hash entries and print them out in the order of the
keys
if ($my_citycode eq "NY")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: jsmith\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
if ($my_citycode eq "LA")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: ldoe\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
}
sub check_citycode
{
my ($hashReference) = @_;
my $citycode = "";
foreach $key (sort keys %$hashReference)
{
if ($key eq "CityCode" && ($$hashReference{$key} eq "NY"))
{
$citycode = 'NY';
}
if ($key eq "CityCode" && ($$hashReference{$key} eq "LA"))
{
$citycode = 'MOPS';
}
}
}
I am trying to send email to multiple recipients using CGI and form. In
the program, I check for the citycodes in the HTML form using subroutine
"check_citycode()". All the form entries will be emailed to different
recipients depending on the city code entered. The problem is, I always get
the message of "No recipient addresses found in the header", though I know I
put the addresses in the perl script.
Thanks in advance for your help.
Nick Li
The code is as the follow:
#!/usr/local/bin/perl
$mailprog = '/usr/lib/sendmail -i -t';
# Process query string
if( $ENV{'REQUEST_METHOD'} eq "POST" )
{
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else
{
$buffer = $ENV{"QUERY_STRING"};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$IN{$name} = $value;
}
$my_citycode = check_citycode();
# Print the page header
print "Content-type: text/html\r\n\r\n";
sub mailComment
{
open(MAIL,"|$mailprog");
# The parameter array contains one hash reference. Assign it to a local
variable.
my ($hashReference) = @_;
# Iterate over the hash entries and print them out in the order of the
keys
if ($my_citycode eq "NY")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: jsmith\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
if ($my_citycode eq "LA")
{
foreach $key (sort keys %$hashReference)
{
print MAIL "To: ldoe\@hotmail.com\n";
print MAIL "From: Operations\@tools.com\n";
print MAIL "Subject: ";
print MAIL "Information Request\n\n";
print MAIL "Here is the message\n");
}
close (MAIL);
}
}
sub check_citycode
{
my ($hashReference) = @_;
my $citycode = "";
foreach $key (sort keys %$hashReference)
{
if ($key eq "CityCode" && ($$hashReference{$key} eq "NY"))
{
$citycode = 'NY';
}
if ($key eq "CityCode" && ($$hashReference{$key} eq "LA"))
{
$citycode = 'MOPS';
}
}
}