Dynamic Batch

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
meddiecap
Forum Newbie
Posts: 8
Joined: Tue Jul 01, 2008 5:14 am

Dynamic Batch

Post by meddiecap »

I want to send a batch to multiple users. So far, I got this:

Code: Select all

        
echo "Email sent";
     
$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
             
$message =& new Swift_Message($title, $contents, "text/html");
             
$recipients =& new Swift_RecipientList();
            
while ($row_customers = mysql_fetch_array($res_customers))
    {   
    $recipients->addTo($row_customers['emailadress']);
    }
 
// just to check:
echo "Sent to: ".$recipients;
 
//NOTE that Cc and Bcc recipients are IGNORED in a batch send
             
$swift->batchSend($message, $recipients, "me@somedomain.com");
 
Some how, the $recipients is not filled, but I don't really know why...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Dynamic Batch

Post by Chris Corbyn »

Does your loop actually run? Have you tried placing an 'echo "something"' inside it just to be sure?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Dynamic Batch

Post by Chris Corbyn »

Oh, hang on. Not sure what it is you're doing here, you can't echo an object like that.

Code: Select all

$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
             
$message =& new Swift_Message($title, $contents, "text/html");
             
$recipients =& new Swift_RecipientList();
           
while ($row_customers = mysql_fetch_array($res_customers))
    {   
    $recipients->addTo($row_customers['emailadress']);
    }
 
//NOTE that Cc and Bcc recipients are IGNORED in a batch send
             
$numSent = $swift->batchSend($message, $recipients, "me@somedomain.com");
 
// just to check:
echo "Sent to: " . $numSent . " recipients";
meddiecap
Forum Newbie
Posts: 8
Joined: Tue Jul 01, 2008 5:14 am

Re: Dynamic Batch

Post by meddiecap »

Yea..I found out that i can echo $recipients like this: print_r($recipients);

Somehow, the loop doesn't loop.

What does work is when I place the while-loop on the outside (or whatever it's called):

Code: Select all

 
while ($row_customers = mysql_fetch_array($res_customers))
{  
$swift =& new Swift(new Swift_Connection_SMTP("smtp.host.tld"));
             
$message =& new Swift_Message($title, $contents, "text/html");
             
$recipients =& new Swift_RecipientList();
           
 
    $recipients->addTo($row_customers['emailadress']);
 
 
//NOTE that Cc and Bcc recipients are IGNORED in a batch send
             
$numSent = $swift->batchSend($message, $recipients, "me@somedomain.com");
 
}
 
// just to check:
echo "Sent to: " . $numSent . " recipients";
 
But that is rather memory expensive I think.

EDIT: Had to change smtp.host.tld to what would apply to me.
Post Reply