$recipients =& new Swift_RecipientList();
do {
$recipients->addTo($para_useremail, $para_username);
} while ($row_subscriber_set = mysql_fetch_assoc($subscriber_set));
$swift=& new Swift_BatchMailer($swift);
$swift->send($message, $recipients, new Swift_Address($mail_emailsource, "Our Name");
// once sent is done, use $swift->getFailedRecipients(); result to update database
If my current set-up is bad and it is better to use batchsend, how would you use Decorator or AntiFlood plugins?
You shouldn't be loading any plugins more than once, so putting the calls to attachPlugin() in the loop is wrong. By doing that you're constantly overriding the plugin settings and thus, something like AntiFlood will never work.
send() also throws exceptions which will potentially halt your script so you'd ideally want to wrap that call in a try/catch.
Using batchSend() will solve both of those problems... just attach the decorator before calling batchSend(), and the same for the AntiFlood plugin. All you need to do is build your entire array of replacements before loading the plugin.
dillion wrote:cheers for your response. I take it that using batchsend is better and I should modify my script accordingly?
It's not better as such... batchSend() just calls send() itself. It's just easier for end-users who don't really care about what goes wrong and would rather let swift handle it If you'd be happy wrapping your send() calls in a try/catch then do that One thing to note is that inside the catch block you'll more than likely want to call $swift->reset() for safe measure.
Chris Corbyn wrote:
It's not better as such... batchSend() just calls send() itself. It's just easier for end-users who don't really care about what goes wrong and would rather let swift handle it If you'd be happy wrapping your send() calls in a try/catch then do that One thing to note is that inside the catch block you'll more than likely want to call $swift->reset() for safe measure.
Meh, just use batchSend()
Heheh - make up your mind!
My current code already has a try/catch but no reset() call. Either way, I will modify the code and use batchSend().