Page 1 of 1

Dynamic Batch

Posted: Mon Jan 26, 2009 5:33 am
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...

Re: Dynamic Batch

Posted: Mon Jan 26, 2009 7:17 am
by Chris Corbyn
Does your loop actually run? Have you tried placing an 'echo "something"' inside it just to be sure?

Re: Dynamic Batch

Posted: Mon Jan 26, 2009 7:19 am
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";

Re: Dynamic Batch

Posted: Mon Jan 26, 2009 7:49 am
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.