Re: [PHP] Is a while loop the most efficient way to send out multiple emails?
> I currently run a few newsletters that go out to small groups of > % 50 to 100 people. I use a while loop to send out the emails. I chose I have a module that does about about 100 emails (10Kb of data per email, which is a decent sized email) in 8 - 10 seconds. (Does around 610 - 625 emails per minute). This is accomplished by skipping PHP's internal mail functionality entirely and making a direct socket connection to the SMTP server. Another benefit of this is that any MySQL delay can be removed from the actual mail functionality by adding all the recipients to the class, and closing the MySQL query - before sending the emails. Ultimately, the speed really depends on the SMTP server. I'm sure with a little hacking, I may be able to get 650 - 675 emails per minute. One faster method of sending bulk emails requires A) having direct access to the filesystem of the mail server, and B) hacking sendmail configuration - which both mean "root" access. I've gotten up to 850 emails per minute with this method. The class is easy to use - basically: $_Mailer = &new mod_sendmail(); $_Mail->setSubject( strText ); $_Mail->setBody( strText ); $_Mail->addRecipient( strName, strEmail ); $_log = $_Mail->sendAll(); The $_log var is an array in the format of: $_log[ strEmail ] = strData strEmail is the intended recipient, and and strData will either be A) the MsgID returned by the SMTP server on success or B) a "0" if failed. This makes it possible to add a function to re-send failed emails later. If you want the socket-based code, just send me a private email to [EMAIL PROTECTED] I'm working on getting a code repository going, but for now, just have to send it to you directly. -- James [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is a while loop the most efficient way to send out multiple emails?
Dave -- ...and then Dave G said... % % PHP Gurus, % I currently run a few newsletters that go out to small groups of % 50 to 100 people. I use a while loop to send out the emails. I chose a ... % about 50 people. I'm not sure exactly, but maybe ten seconds, possibly % as high as twenty. % Soon I will be creating a script to send out an email to 500 ... % So my question is, is there a way more efficient than while % loops to send out multiple emails with personalized information? Is it % the mail() command that takes time, or the mysql_fetch_array(), or both? % Any suggestions would be greatly appreciated. 0) That really should be $member['name'] and $member['email'] instead of bare indices, you know :-) 1) It's definitely the mail() command, and that's dependent on the underlying mail system. 2) Driving this from the browser is probably a bad way to go because you will always be fighting timeout issues *and* what about a broken connection not because of a timeout? 3) If you want full personalization, you're stuck with individual emails, but lots of mailing list software out there can handle VERPing and, say, footers and save you a whopping lot of work. 4) I did some work this summer on a mass mail script; with a little script tweaking and some (but not onerous) qmail tweaking, I got our times down to around 100ms per email. That puts us sending about 30k [personalized] emails per hour, which is an order of magnitude faster than the speed of the guys who lost the contract to us :-) It's discussed on the list a bit; check the archives. HTH & HAND & Happy Holidays :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
Re: [PHP] Is a while loop the most efficient way to send out multiple emails?
Dave G wrote: So my question is, is there a way more efficient than while loops to send out multiple emails with personalized information? Is it the mail() command that takes time, or the mysql_fetch_array(), or both? Any suggestions would be greatly appreciated. It's the mail() function. I've seen a class that connects to smtp server and sends all emails in one connection, author claimed it was faster than the built-in mail() function. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is a while loop the most efficient way to send out multiple emails?
At 05:37 PM 12/30/2003 +0900, Dave G wrote: PHP Gurus, I currently run a few newsletters that go out to small groups of 50 to 100 people. I use a while loop to send out the emails. I chose a while loop as opposed to just taking all the emails and putting them in the CC field because I wanted to personalize each email with a greeting that included the recipients name and other personalized information. It looks like: while ($member = mysql_fetch_array($sqlQueryResult) { $content = "Hi, {$member[name]}. Your email address is {$member[email]}"; mail ($member[email], $subject, $content) } When I execute my script, it takes a little time to go through about 50 people. I'm not sure exactly, but maybe ten seconds, possibly as high as twenty. Soon I will be creating a script to send out an email to 500 people, with the possibility that it will grow to 1000. I'm concerned that the while loop will take ten times as long, and not only be a drain on the server, but also run the risk of my browser timing out waiting for a response to confirm all mails were sent. So my question is, is there a way more efficient than while loops to send out multiple emails with personalized information? Is it the mail() command that takes time, or the mysql_fetch_array(), or both? Any suggestions would be greatly appreciated. -- Yoroshiku! Dave G [EMAIL PROTECTED] Dave, This goes out to 900 people every night, I just bought myself some time by adding this at the bottom of the while loop: // give ourselves more time set_time_limit( 20 ); I also echo the recipient's email & an OK/Fail, depending on what mail() returns, to the browser so that I can see the progress. HTH - Miles -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Is a while loop the most efficient way to send out multiple emails?
PHP Gurus, I currently run a few newsletters that go out to small groups of 50 to 100 people. I use a while loop to send out the emails. I chose a while loop as opposed to just taking all the emails and putting them in the CC field because I wanted to personalize each email with a greeting that included the recipients name and other personalized information. It looks like: while ($member = mysql_fetch_array($sqlQueryResult) { $content = "Hi, {$member[name]}. Your email address is {$member[email]}"; mail ($member[email], $subject, $content) } When I execute my script, it takes a little time to go through about 50 people. I'm not sure exactly, but maybe ten seconds, possibly as high as twenty. Soon I will be creating a script to send out an email to 500 people, with the possibility that it will grow to 1000. I'm concerned that the while loop will take ten times as long, and not only be a drain on the server, but also run the risk of my browser timing out waiting for a response to confirm all mails were sent. So my question is, is there a way more efficient than while loops to send out multiple emails with personalized information? Is it the mail() command that takes time, or the mysql_fetch_array(), or both? Any suggestions would be greatly appreciated. -- Yoroshiku! Dave G [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php