MySQL loop. Suppressing errors + final log/error report.

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
ohmish
Forum Newbie
Posts: 1
Joined: Tue Nov 17, 2009 6:35 am

MySQL loop. Suppressing errors + final log/error report.

Post by ohmish »

Hi

I am using the good swift mailer (4.0.5) to loop through a mysql table, and by each email address I'm checking if the mail was sent - If so: mark it as ok/sent in the database.

Is there any way to suppress realtime errors (Uncaught exception) that stops my loop?
I have tried @$mailer->send($message) but it doesnt work.

Hope someone can guide me a bit. Thank you.

Code: Select all

<?php
 
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance($smtphost, 25)
;
$mailer = Swift_Mailer::newInstance($transport);
$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(100));
$message = Swift_Message::newInstance()
->setSubject($mailsubject)
->setFrom($servermailhost)
->setReplyTo($servermailhost)
->setReturnPath($servermailbounce)
->setBody($mailtext)
->setCharset('iso-8859-1')
;
 
//ArrayLogger
$logger = new Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
 
$linkresult = @mysql_query("SELECT * FROM maillist WHERE sentcheck=0 ORDER BY timestamp DESC");
if (@mysql_num_rows($linkresult) > 0) {
 
while ($nrow = @mysql_fetch_array($linkresult)) {
 
    $bid = $nrow['id'];
    $bname = $nrow['thename'];
    $bemail = $nrow['theemail'];
    if (strlen($bname)>1) {
    $message->setTo($bemail, $bname);
    } else {
    $message->setTo($bemail);
    }
 
if ($mailer->send($message)) {
@mysql_query ("UPDATE maillist SET sentcheck=1 WHERE id=$bid LIMIT 1");
}
 
}
 
@mysql_query("UPDATE newsletters SET sentstatus='".$logger->dump()."' WHERE id=$newsletterid");
header ('Location: '.$root.'newsletter/sentok/');
 
}
 
?>
Post Reply