Problem with email

Discussion in 'Perl Misc' started by Ning li, Dec 27, 2003.

  1. Ning li

    Ning li Guest

    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';
    }
    }
    }
     
    Ning li, Dec 27, 2003
    #1
    1. Advertising

  2. Ning li wrote:
    > 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.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Dec 27, 2003
    #2
    1. Advertising

  3. "Ning li" <> wrote in message
    news:ZF9Hb.245368$...
    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
     
    Ragnar Hafstað, Dec 27, 2003
    #3
  4. Ning li <> wrote:

    > 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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Dec 27, 2003
    #4
  5. Ning li

    someone Guest

    > 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.
     
    someone, Dec 27, 2003
    #5
  6. Ning li

    someone Guest

    $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.
     
    someone, Dec 27, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter
    Replies:
    0
    Views:
    3,385
    Peter
    Jul 1, 2003
  2. John Silver
    Replies:
    0
    Views:
    617
    John Silver
    Feb 4, 2005
  3. Nico Grubert
    Replies:
    0
    Views:
    885
    Nico Grubert
    Dec 8, 2006
  4. Fredrik Lundh
    Replies:
    0
    Views:
    451
    Fredrik Lundh
    Dec 8, 2006
  5. ecureuil
    Replies:
    0
    Views:
    329
    ecureuil
    May 28, 2006
Loading...

Share This Page