i'm using swift mailer and i've got a problem with sending. The mailer fails several mail adresses.
I need to build in the script some kind of loop which checks in the mysql database which mailadresses are send correctly and which not.
The ones that didnt send needs to be send again.
I tryd for days to figure it out but i'm really stuck...
Below i post the scipt i'm using. Hopefully one of you can help me make the send loop and check...
Thanks in advance....
Code: Select all
$hostname = '********';
$username = '********';
$password = '********';
$database = '********';
mysql_connect("$hostname","$username","$password");
mysql_select_db("$database");
require_once "lib/Swift.php";
require_once "lib/Swift/Log.php";
require_once "lib/Swift/LogContainer.php";
require_once "lib/Swift/Connection/SMTP.php";
require_once "lib/Swift/Plugin/Decorator.php";
require_once "lib/Swift/Plugin/AntiFlood.php";
$log = Swift_LogContainer::getLog();
$log->setLogLevel(3);
$conn =& new Swift_Connection_SMTP("smtp1.********.net", 25);
$conn->setUsername("noreply@********.com");
$conn->setpassword("********");
$swift = new Swift ($conn);
$from = new Swift_Address ('noreply@********.com', 'Mailing');
$subj = 'Mailing';
$body = 'My HTML mailing';
$msg = new Swift_Message ($subj, $body, 'text/html');
$recipients = new Swift_RecipientList();
$sql = "SELECT email, naam FROM mailing";
$result = mysql_query($sql);
$to = array();
$replacements = array();
while($aRow = mysql_fetch_assoc($result)){
$to[] = new Swift_Address ($aRow['email']);
$replacements[$aRow['email']] = array('{naam}' => $aRow['naam']);
}
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
foreach ($to as $address) {
$recipients->addTo ($address);
}
//Reconnect after 20 emails, but wait for 5 seconds first
$swift->attachPlugin(new Swift_Plugin_AntiFlood(20, 5), "anti-flood");
$number_sent = $swift->batchSend ($msg, $recipients, $from);
$swift->disconnect ();
echo 'De mailing failed at the following recipients:';
echo '<pre>';
print_r ($log->getFailedRecipients());
echo '</pre>';
echo 'Message sent to ' . $number_sent . ' recipients.';