Re: Re: mail() takes too much time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Lasar wrote:
I run pretty simple mail group distribution program that uses php/mysql and the mail() function. I adapted it from an open source script. Most of the time it runs well. But it does take a while to run through all 150 members of the list. So I'm half glad that I don't have a list of 1000 people or more.

Any way to optimize the mail function in terms of speed? Probably too vague a question, sorry.


Have a look at the Swift Mailer package:

http://www.swiftmailer.org/

I use it to send out well over 1000 mails at a time and it works quite fine for me. Check out the anti-flood extension for sending large batches:

$swift = new Swift(new Swift_Connection_SMTP('localhost'), 'domain.org');
	

/* 100 mails per batch with a 30 second pause between batches
 */
$swift->attachPlugin(new Swift_Plugin_AntiFlood(100, 30), 'anti-flood');


/* list of recipients is an object wrapping an array
 */
$recipients = new Swift_RecipientList();
$recipients->addTo('foo@xxxxxxx', 'foo bar');


/* headers
 */
$message = new Swift_Message('the subject');
$message->setCharset('utf-8');
$message->setReplyTo('reply@xxxxxxxxxx');
$message->setReturnPath('return@xxxxxxxxxx');
$message->headers->set('Errors-To', 'errors@xxxxxxxxxx');


/* multipart is a breeze
 */
$message->attach(new Swift_Message_Part($plain_content));
$message->attach(new Swift_Message_Part($html_content, 'text/html'));


/* if you're sending the mails from, eg. an admin page ...
 */
set_time_limit(0);
ignore_user_abort();
flush();


/* send it out
 */
$num_sent = $swift->batchSend($message, $recipients, new Swift_Address('from@xxxxxxxxxx', 'from'));

This really should be rolled into the PEAR project, IMO.

brian

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux