nother email not sent using 2 loops this time

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
choubix
Forum Commoner
Posts: 42
Joined: Tue Nov 06, 2007 12:21 pm

nother email not sent using 2 loops this time

Post by choubix »

hello,

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);
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!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Could you describe "doesn't work" a little more in detail please? :)
choubix
Forum Commoner
Posts: 42
Joined: Tue Nov 06, 2007 12:21 pm

Post by choubix »

hi chris,

sorry for wasting your time...
I have foudn out what the problem was: I forgot to include the files... I focused on debugging my email and placing the code in relevant places and forgot the essential... :(

by the way: am i the only one having troubles connecting on the forum ??
it seems it is out of service most of the time.
Post Reply