Page 1 of 1

Problem with Addto using batchsend and mysql data

Posted: Mon Jan 25, 2010 5:58 am
by mekat
Hi Guys,
I am new to the forum and please forgive me in advance if the answer is somewhere in here (but could not find it).

I am using swiftmailer version 4, which is potentially a very usefull tool for me. However, I am stuck with sending a newsletter to a bunch of people. If I hardcode the email addresses everything is going fine. But I am actually using a database to retreive email addresses. I actually thought I could simply loop to retreive these using the "addto" function. Please see my code below :

Code: Select all

 
setFrom(array('something@somedomain.com' => 'Newsletter'))
->setSender('something@somedomain.com')
->setReturnPath('something@somedomain.com')
->setBody('message')
;
 
[color=#BF0000]// loop to add new recipient, this doesn't work !!![/color]
while ($donnees3 = mysql_fetch_array($retour3))
{
$message->addTo($donnees3['email']);
} 
 
[color=#BF0000]//this works perfectly !![/color]
$message->addTo('something@somedomain.com');
 
//Send the message
$numSent = $mailer->batchSend($message);
 
 

By the way, if I try this code below, email adresses within the database echo real fine.

Code: Select all

 
while ($donnees3 = mysql_fetch_array($retour3))
{
echo $donnees3['email'] ;
}
Can anyone help ?
Thanks in advance...

Re: Problem with Addto using batchsend and mysql data

Posted: Sat Feb 06, 2010 11:37 am
by Trance-formation
I use setTo and pass an array (actually I pass an associative array of the form

Code: Select all

array('name=>'email', name2'=>'email2',...);
which I build from a loop from my mysql query)

Hope that helps