Alice Wonder has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I usually do not program in perl, so I apologize that I do not even know where to begin looking for solution.
Web app I am building in php, I am trying to be very careful with user e-mails to avoid data leaks and they are in a different database then the web app uses, the web app cues a message to a user id when it wants to e-mail user.
That is where perl comes in. I want perl script running from cron every 10 minutes to fetch messages from the cue, associate e-mail with user id, and send it.
sendmail (er, postfix...) is working on the server and sending mail via /usr/sbin/sendmail works. Host is CentOS 7 x86_64
The error I get from the script:
Name "main::id" used only once: possible typo at sendmessages.pl line +39. Use of uninitialized value in lc at /usr/share/perl5/vendor_perl/Email +/Simple/Header.pm line 181. Use of uninitialized value in lc at /usr/share/perl5/vendor_perl/Email +/Simple/Header.pm line 181. Use of uninitialized value in lc at /usr/share/perl5/vendor_perl/Email +/Simple/Header.pm line 181. no recipients Trace begun at /usr/share/perl5/vendor_perl/Email/Sender/Simple.pm lin +e 107 Email::Sender::Simple::send_email('Email::Sender::Simple', 'Email::Abs +tract=ARRAY(0x34f66e8)', 'HASH(0x35be030)') called at /usr/share/perl +5/vendor_perl/Email/Sender/Role/CommonSending.pm line 27 Email::Sender::Role::CommonSending::__ANON__ at /usr/share/perl5/vendo +r_perl/Try/Tiny.pm line 71 eval {...} at /usr/share/perl5/vendor_perl/Try/Tiny.pm line 67 Try::Tiny::try('CODE(0x35bdfd0)', 'Try::Tiny::Catch=REF(0x34ccf28)') c +alled at /usr/share/perl5/vendor_perl/Email/Sender/Role/CommonSending +.pm line 40 Email::Sender::Role::CommonSending::send('Email::Sender::Simple', 'ali +cewonder@###') called at /usr/share/perl5/vendor_perl/Sub/Exporter/Ut +il.pm line 18 Sub::Exporter::Util::__ANON__('alicewonder@###') called at sendmessage +s.pl line 64 (### is hiding the valid domain, I h8 spam)
(the main::id I understand, it will be used in code once I get send working)
The code:
#!/usr/bin/perl -w use DBI; $dbh = DBI->connect('dbi:mysql:alicenet','####','####', { mysql_enable +_utf8 => 1, }) or die "Connection Error: $DBI::errstr\n"; $adbh = DBI->connect('dbi:mysql:anetauth','####','####', { mysql_enabl +e_utf8 => 1, }) or die "Connection Error: $DBI::errstr\n"; #count the messages $sql = "SELECT COUNT(id) AS count FROM mailcue WHERE failed < 3 AND la +sttry < (NOW() - INTERVAL 90 MINUTE)"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI:: errstr\n"; @row = $sth->fetchrow; $count = $row[0]; #max number of cued messages to fetch $n = ($count < 180)? 30 : int($count/6); #seconds to sleep between action - we want to finish in 8 minutes $sleep = int(480/$n); $sql = "SELECT id,userid,subject,message FROM mailcue WHERE failed < 3 + AND lasttry < (NOW() - INTERVAL 90 MINUTE) ORDER BY id LIMIT $n"; $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { $id = $row[0]; $userid = $row[1]; $subject = $row[2]; $body = $row[3]; $asql = "SELECT email FROM userauth WHERE id=$userid"; $asth = $adbh->prepare($asql); $asth->execute; @arow = $asth->fetchrow; $email = $arow[0]; # okay we can send this futher mocker use Email::MIME; my $message = Email::MIME->create( header_str => [ From => 'anetbot@domblogger.net', To => $email, Subject => $subject, ], attributes => { encoding => '8bit', charset => 'utf-8', }, body_str => $body, ); # send it use Email::Sender::Simple qw(sendmail); my $response = sendmail($email); # on success, delete from mailcue. On fail, increment failed field in + mailcue and insert error message into error field of mailcue. sleep $sleep; }
Thank you for any assistance in figuring out how to fix that error.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of uninitialized value in lc
by toolic (Bishop) on Nov 08, 2014 at 13:34 UTC | |
by Alice Wonder (Initiate) on Nov 08, 2014 at 13:45 UTC | |
by poj (Abbot) on Nov 08, 2014 at 19:33 UTC | |
|
Re: Use of uninitialized value in lc
by ww (Archbishop) on Nov 08, 2014 at 14:22 UTC | |
|
Re: Use of uninitialized value in lc
by chacham (Prior) on Nov 09, 2014 at 04:46 UTC | |
by FloydATC (Deacon) on Nov 09, 2014 at 18:13 UTC | |
by chacham (Prior) on Nov 09, 2014 at 18:58 UTC |