nother email not sent using 2 loops this time
Posted: Tue Nov 20, 2007 10:17 am
hello,
I am using this code:
but it doesnt woork.
I guess it comes for the for each loop and $recipient.
I have tried a few combinations without success.
does anyone have an idea of what's wrong please?
thanks!
I am using this code:
Code: Select all
$smtp =& new Swift_Connection_SMTP("smtp.mydomain.com");
$smtp->attachAuthenticator(new Swift_Authenticator_LOGIN());
$smtp->setUsername("login");
$smtp->setPassword("password");
$swift =& new Swift($smtp);
//Create the message
$message =& new Swift_Message("Dear {fname} {lname} blablabla", "Congratulations, you have {points} on {name}! Have a great day!");
$recipients =& new Swift_RecipientList();
$replacements = array();
//extract all values from array stored in the session
foreach($_SESSION['winners'] as $key=>$value)
{
$query = ("SELECT clients.lname, clients.fname, clients.email, clients.points, gifts.name
FROM clients, gifts
WHERE clients.id_clients = '$value'
AND gifts.id_gifts = '$id_gifts'
GROUP BY '$value'"
);
$result = mysql_query($query) or die('Query failed. ' . mysql_error());
while ($row = mysql_fetch_assoc($result))
{
$replacements[$row['email']] = array("{fname}" => $row['fname'], "{lname}" => $row['lname'], "{points}" => $row['points'], "{name}" => $row['name']);
$recipients->addTo($row['email']);
//echo ' '.$row['fname'].' '.$row['lname'].' '.$row['points'].' '.$row['name'].' '.$row['email'].' <br>';
}
}
//Load the plugin with these replacements
$swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
//Now check if Swift actually sends it
if($swift->batchSend($message, $recipients, "admin@mydomain.com"))
{
echo 'ok';
}
else
{
echo 'nok';
}
$swift->disconnect();
mysql_free_result($result);I guess it comes for the for each loop and $recipient.
I have tried a few combinations without success.
does anyone have an idea of what's wrong please?
thanks!