Possible bug?
Posted: Mon Jan 07, 2008 9:16 pm
Consider the following code, in which I am using swift along with smtp authentication, decorator plugin and anti-flood plugin.
The output of this script is:
That's all fine and dandy.
However a few users have complained to me that their username is wrong. I'm wondering what happens to the $replacements array when an email can't be sent for whatever reason? Is this a problem in the swift decorator plugin or my code? Everything seemed fine when all of the emails were sent when I had less members. I'm just grabbing at straws here, but I'm thinking when an email can't be sent it throws off the replacements array.
Code: Select all
set_time_limit(0);
ignore_user_abort(true);
if (empty($_POST['emailSubject']) || empty($_POST['emailBody']))
{
die('Please provide an email body AND a subject');
}
$subject = stripslashes($_POST['emailSubject']);
$body = stripslashes($_POST['emailBody']);
//load in the components
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Swift.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Swift/Connection/SMTP.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Swift/Plugin/Decorator.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Swift/Plugin/AntiFlood.php';
//load the SMTP connection and authenticate
$smtp = new Swift_Connection_SMTP('smtp.1and1.com', 25);
$smtp->setUsername('me@mydomain.tld');
$smtp->setpassword('password');
//start up swift with our SMTP connection
$swift = new Swift($smtp);
//email message with subject only
$message = new Swift_Message($subject);
//add our components
$message->attach(new Swift_Message_Part(strip_tags($body)));
$message->attach(new Swift_Message_Part($body, 'text/html'));
//recipient list
$recipients = new Swift_RecipientList();
//replacements array
$replacements = array();
//grab our email list, loop through adding to recipients and populating the replacements array
$r = mysql_query("SELECT `email`, `username` FROM `users` WHERE `emailGeneral` = 1") or die(mysql_error());
while ($a = mysql_fetch_assoc($r))
{
$recipients->addTo($a['email']);
$replacements[$a['email']] = array('{user}' => $a['username']);
}
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), 'decorator');
//Reconnect after 90 emails, but wait for 10 seconds first
$swift->attachPlugin(new Swift_Plugin_AntiFlood(90, 10), 'anti-flood');
//send
$numSent = $swift->batchSend($message, $recipients, 'me@mydomain.tld');
echo $numSent . ' emails sent out of ' . mysql_num_rows($r) . ' possible!';Code: Select all
274 emails sent out of 276 possible!However a few users have complained to me that their username is wrong. I'm wondering what happens to the $replacements array when an email can't be sent for whatever reason? Is this a problem in the swift decorator plugin or my code? Everything seemed fine when all of the emails were sent when I had less members. I'm just grabbing at straws here, but I'm thinking when an email can't be sent it throws off the replacements array.