develooper Front page | perl.beginners | Postings from February 2002

OO perl problem

From:
Fitzpatrick, Matthew
Date:
February 6, 2002 07:48
Subject:
OO perl problem
Message ID:
A0982A9E90839843BE0D180F6DC17F41016488@ECIMAIL
Hello, my name is matthew fitzpatrick, and i am having some small difficulty in my implimentation of Mail::Sender. 

The problem is that when there are multiple calls to $sender->MailFile or $sender->MailMsg in my loop, only the first match for each MailFile or MailMsg actually gets sent with the email.  I instantiate and close the $sender reference with each iteration of the loop, i don't know why it's not working past the first call.

I have attached a snippet of code:

use Mail::Sender;

# here would be a DBI query that fetchrow_array()'s a series
# of unique message identifiers
while (@arr_uniqID=$sth_uniqID->fetchrow_array())
{
	emailRequests($arr_uniqID[0],$emailAddr);
}
#
# the problem is in the following subroutine called from the above loop.  
# If the subroutine is iterated through n times in the loop,
# only the first MailFile method in all 50 iterations causes a message to be sent, and 
# only the first MailMsg gets sent.  I don't know why 
# this is the case since I declare $sender, and call Close() in the subroutine
#

sub emailRequests($$)
{
        my $uniq_id=shift(@_);
        my $emailAddr=shift(@_);

        my $sender = new Mail::Sender
        {
                smtp => 'smtp.goatheckler.com',
                from => 'mfitzpatrick@ezecastle.com'
        };

        my $str_attachFiles='';

        print "\tMessage Matched: $uniq_id\n";

        my $str_selectMsg="select message from messages where uniq_id='$uniq_id'";
        $sth_selectMsg=$dbh->prepare("$str_selectMsg");
        $sth_selectMsg->execute();
        my @arr_msgContent=$sth_selectMsg->fetchrow_array();
        $sth_selectMsg->finish();

        my $str_selectURL="select url from attachments where uniq_id='$uniq_id'";
        $sth_selectURL=$dbh->prepare("$str_selectURL");
        $sth_selectURL->execute();
        while (my @arr_selectURL=$sth_selectURL->fetchrow_array())
        {
                $str_attachFiles.="/var/www/html-ssl/uploads/$arr_selectURL[0],";
        }
        $sth_selectURL->finish();

        if ($str_attachFiles)
        {
                $str_attachFiles=~s/,$//g;
                $sender->MailFile
                ({
                        to=>"$emailAddr",
                        subject=>'Sirios READER Search Results',
                        msg=>"$arr_msgContent[0]",
                        file=>"$str_attachFiles"
                });
        }
        else
        {
                $sender->MailMsg
                ({
                        to=>"$emailAddr",
                        subject=>'Sirios READER Search Results',
                        msg=>"$arr_msgContent[0]"
                });
        }
        $sender->Close();
}



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About