Re: Re: mail() takes too much time
| From: | brian | Date: | Mon, 03 Sep 2007 17:29:44 +0000 |
| Subject: | Re: Re: mail() takes too much time | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-261649@lists.php.net to get a copy of this message | ||
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@bar.com', 'foo bar'); /* headers */ $message = new Swift_Message('the subject'); $message->setCharset('utf-8'); $message->setReplyTo('reply@domain.com'); $message->setReturnPath('return@domain.com'); $message->headers->set('Errors-To', 'errors@domain.com'); /* 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@domain.com', 'from')); This really should be rolled into the PEAR project, IMO. brian