Batch sending
Posted: Wed Nov 28, 2007 8:44 am
I've followed the instructions for batch sending (with replacements), from the swiftmailer wiki.
The following code is setup to use 2 test emails for the moment:
Ignore the test mode part, that makes use of an option on the previous form.
My question is how to you control how many mails swift sends per batch? Or does it send them all in one go?
Also does the above look right?
The following code is setup to use 2 test emails for the moment:
Code: Select all
<?php
//CREATE AND SEND EMAILS //
//Start Swift
$swift =& new Swift(new Swift_Connection_SMTP("127.0.0.1"));
//Set message subject
$message =& new Swift_Message($subject);
$message->attach(new Swift_Message_Part('<html><body>'.$mail_body.'</body></html>', 'text/html'));
$recipients =& new Swift_RecipientList();
$replacements = array();
if ($_POST['xMode']=='1')
{
$whereClause = "(email='testa@testing.com' OR email='testb@testing.com')";
}
else
{
$whereClause = "(email='test1@testing.com' OR email='test2@testing.com')";
}
$customers = "SELECT email,forename,surname FROM customers WHERE ".$whereClause."";
$cq = mysql_query($customers) or die("Query Customers: $customers Failed".mysql_error());
while ($cr = mysql_fetch_assoc($cq))
{
//Specify the list of replacements as a 2-d array
$replacements[$cr['email']] = array("{forename}" => $cr['forename'], "{surname}" => $cr['surname']);
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
$recipients->addTo($cr['email']);
}
//Send messages
$swift->batchSend($message, $recipients, "from@testing.com");
$swift->disconnect();
?>My question is how to you control how many mails swift sends per batch? Or does it send them all in one go?
Also does the above look right?