Re: bulk emailer

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

 



> what i'm currently doing:
> -using mysql_fetcharray() to loop through an array of query results
> -for each iteration of the loop, get an email address from the current row
> in the result set, and use it with the mail() function to send out an
> individual email to that email address, then echo out a confirmation in
> HTML so that the user will know that an email has been sent
> -this is repeated for each email address found in the result set
> problem with this is: with large result sets (some of my result sets come
> up with a few thousand email addresses), users have to wait a long time
> for the confirmation messages to print out to their browser, sometimes it
> seems that not all the messages go through

Ye Gods!

The mail() function is designed for quickie one-off emails, not sending
out thousands.  Hell, it can't even handle dozens, not reliably, at least
not on some hardware/connections.

Mostly because *EVERY* time you call mail() it fires up sendmail (a large
application) and that ends up (sooner or later) opening up and tearing
down an SMTP connection for each email you send.

Your options include:
Using Bcc: to send *ONE* email to 10,000 people.
Your sendmail may or may not allow that, and spam filters may or may not
kill some because they *are* Bcc.

Use the mail class from http://phpclasses.org to talk directly to an SMTP
server, or roll your own.

Actually, the mail class there can do it with sendmail as well, though
with a few thousand emails, it probably won't be very efficient.

For sure, your user is gonna wait a LONG time for a couple thousand
individual emails, no matter what you do.

> what i've tried:
> -using mysql_fetcharray() to loop through an array of query results
> -for each iteration of the loop, get an email address from the current row
> in the result set, and append it to a long strong called $bcc
> -then i plug the value of $bcc into the mail() command, which is issued
> only once at the end of the loop
> -this method seems to work better, does not take as long, HTML
> confirmation messages get printed faster since mail() function is only
> called once at the end of the loop, only one email is sent (with a long
> BCC field), so it doesn't bog the server down so much
> problem with this method is: with large result sets (some of my result
> sets come up with a few thousand email addresses), the BCC field is so
> large that it is too large for the mail server to send out

Ah, good try though.

> has anyone done a bulk emailer script to send out mass emails?  if you
> have any advice re: methodology, i'd like to hear it.

You can also build up, say, 200 at a time, then call mail every 200 emails
with Bcc, so your sendmail can handle it.

Check the return value from mail for success/failure.  Error-checking good!

It's also a good idea to sort your emails by their destination.

A cheap easy way to do this is to sort by reverse(email) -- IE php.net
turns into ten.php and northwestern.edu turns into ude.nretsewhtron.

This helps the SMTP by having all the AOL addresses together, so its
connection to AOL can be re-used for the next 200 recipients.

A better answer, all around, might be to use a mailing list software
package for sending bulk email -- They've been fine-tuned to be really
good at it.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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