Duplicates sending
Posted: Mon Oct 08, 2007 10:51 pm
I'm coding a permanent cron loop to send all the emails continuously but I got a problem. Sometimes it sends 2,3 or 4 emails to the same person, randomly.
I'm using PHP 5 and version 3.3.1
Here's the main loop code :
As I update every email flag everytime I don't understand how I could send many times the same email (knowing that there's no duplicates in newsletter table).
Thanks for your help.
I'm using PHP 5 and version 3.3.1
Here's the main loop code :
Code: Select all
while($stop==false) {
$sql = "select uniqueid,useremail,mailid from newsletter where tosend=1 and sent=0 order by mailid limit $nbmails";
$res = $db->doSelect($sql);
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
while($row = $db->getNextRow()) {
$mail->get($row[mailid]);
$mess = stripslashes(str_ireplace("{usernum}",$row[uniqueid],$mail->message));
try {
$message =& new Swift_Message($mail->subject, $mess,"text/html");
if($swift->send($message,$row[useremail],"***@***.com")) {
$sql = "update newsletter set sent=1,tosend=0 where uniqueid=".$row[uniqueid];
} else {
$sql = "update newsletter set sent=1,tosend=0,bounce=1 where uniqueid=".$row[uniqueid];
}
$db->doUpdate($sql);
} catch (Swift_ConnectionException $e) {
$logs->add($e->getMessage(),$row[mailid]);
} catch (Swift_Message_MimeException $e) {
$logs->add($e->getMessage(),$row[mailid]);
}
}
$swift->disconnect();
sleep(20);
}Thanks for your help.