Page 1 of 1

to big arrays for batch and template mode

Posted: Wed Nov 29, 2006 2:34 pm
by whitewindow
Hallo

i would like to send many emails (like 50.000)

i get the emails and user from a mysql db and i can not store this in arrays (max mb size is 8MB for php)
i can increase the php max value but i think this is not a good idea ?

how can i use the template and the AntiFlood Plugins ?

i think i can only use the standard send option
every email a ne send()


any ideas

sample code from me

Code: Select all

require('Swift-2.1.17-php4/Swift/Connection/SMTP.php');
require('Swift-2.1.17-php4/Swift.php');
require('Swift-2.1.17-php4/Swift/Plugin/AntiFlood.php');
require('Swift-2.1.17-php4/Swift/Plugin/Template.php');
require('Swift-2.1.17-php4/Swift/Plugin/Swift_Plugin_CustomiseEachEmail.php');

$sql="SELECT  ";

				
		$dbh = new db_handler();	

		$dbh->dbQueryOnce($sql);



		while ($row = $dbh->dbGetRow())
		{
			echo $row['nickname'];
               		if($row['nickname'])
			 $nickname =  trim($row['nickname']);
			else 
			 $nickname = $row['email'];

        		//$email[] = array($nickname, $row['email']);
                        //$user[] = array('id'=>$row['user_id'], 'name'=>$nickname);
		}

		//print_r($user);
the swift code i would like to use


Code: Select all

$mailer = new Swift(new Swift_Connection_SMTP('localhost'));

$mailer->loadPlugin(new Swift_Plugin_AntiFlood(100, 30));




$recipients = array(
        'you@examplel.com',
        'me@example.com',
        );


$tpl = array (
 array ('id' => '1' , 'foo' => 'First email' , 'name' => 'Jhon'),
 array ('id' => '2' , 'foo' => 'second email', 'name' => 'whwi')
);

         $mailer->loadPlugin(new Swift_Plugin_CustomiseEachEmail($tpl));
         //$mailer->loadPlugin(new Swift_Plugin_Template($tpl));

        //Add as many parts as you need here
        $mailer->addPart('Some {foo} plain  {name} text part');
        $mailer->addPart(' {id} Some HTML <strong>part with bold</strong> text', 'text/html');


        //Make the script run until it's finished in the background
        set_time_limit(0); ignore_user_abort();
        echo "Close the browser window now...";
        flush(); ob_flush();

        //Leaving the body out of send() makes the mailer send a multipart message
        echo $mailer->send(
                $recipients,
                '"you" <webmaster@you.com>',
                'Some Subject'
        );
  	print_r($mailer->transactions);
        print_r($mailer->getFailedRecipients());

        $mailer->close();
i hope anybody have a hint for me

whwi

Posted: Wed Nov 29, 2006 3:18 pm
by Chris Corbyn
Just call send() in the loop which iterates over your data set for now. You can addPart() in that same loop and after every send() it automatically flushes what was sent anyway.

Version 3 is likely to be ready in under 2 weeks from now which has been built around many of the common requests I get by email. One of which is this whole templating issue. As a result, (this is already coded) in version 3 you don't need any complicated plugins to customise each email. You have the control over looping, swift deals with the caching (in a clever way which figures out which bits you've customised each time... hence it's not expensive).

I would avoid trying 50,000 in one shot but if you are doing so the AntiFlood plugin still works when you call send() in a loop so that will be fine. Hold on for a fortnight and this will be so much easier though :)