Problem with email

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';
}
}
}
 
G

Gunnar Hjalmarsson

Ning said:
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.

Nobody here is able to help you based on the information you posted.
Besides, the script seems to be very old, and the question is if
someone would be willing to assist even if you provided the relevant
info.

I'd suggest that you ask the script author for help.
 
R

Ragnar Hafstað

snipped problem and most of a script that can't possibly work
$my_citycode = check_citycode();

...
sub check_citycode
{
my ($hashReference) = @_;

now what is the value of $hashReference?


gnari
 
T

Tad McClellan

Ning li said:
Thanks in advance for your help.
The code is as the follow:

#!/usr/local/bin/perl


Show your real code (shebangs do not work when indented).

Enable warnings.

Enable strict.

Use CGI.pm to parse form values.

Check the return value from open().

Check the return value from close() if the open() used a pipe.

Then post the de-crufted version of your code.

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");
}


You do not use $key anywhere in the loop. Why not?

Why must the keys be sorted?
 
S

someone

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");
}

I suspect that the above loop doesn't execute at all.
therefore, no data is fed to the sendmail program.
check out the values of your $my_citycode and %$hashReference.
 
S

someone

$my_citycode = check_citycode();


sub check_citycode
{
my ($hashReference) = @_;
my $citycode = "";

foreach $key (sort keys %$hashReference)
{
if ($key eq "CityCode" && ($$hashReference{$key} eq "NY"))
{
$citycode = 'NY';


As shown above, you did *not* pass anything to the sub check_citycode.
therefore, $my_citycode has an undefined value. and nothing is done in the
sub mailComment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top