Problem with Addto using batchsend and mysql data

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
mekat
Forum Newbie
Posts: 1
Joined: Mon Jan 25, 2010 5:42 am

Problem with Addto using batchsend and mysql data

Post 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...
Trance-formation
Forum Newbie
Posts: 11
Joined: Tue Jul 17, 2007 6:31 am

Re: Problem with Addto using batchsend and mysql data

Post 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
Post Reply