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('[EMAIL PROTECTED]', 'foo bar');


/* headers
 */
$message = new Swift_Message('the subject');
$message->setCharset('utf-8');
$message->setReplyTo('[EMAIL PROTECTED]');
$message->setReturnPath('[EMAIL PROTECTED]');
$message->headers->set('Errors-To', '[EMAIL PROTECTED]');


/* 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('[EMAIL PROTECTED]', '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

Reply via email to