views:

927

answers:

5

I am using php and mysql

I am going to send 10k++ (ten thousands plus) emails to update my subscribers, and this is the first time I am going to send them. I will use php mail function, basically here is what I will do:

First get the data from database:

Select name, email FROM data

After that, using while loop to send the data:

while($r = mysql_fetch_assoc($exe)){
    ...
    if($mail){
        echo "success<br>";
    } else {
        echo "failed<br>";
    }
}
echo "Sent all";

I include the if.. else statement, to ensure that each email is sent successfully. Is there anything I need to take care of? Will I have any problems when SENDING TO 10K++ users??

Is there a limit of numbers of emails that you are going to sent? Please advise, I am new to php. Thanks

+4  A: 

No limit to the emails number, but there is the time limit of the PHP script. See the max_execution_time set in your php.ini, typically it's 20 or 30 seconds. If you don't know that, use phpinfo() to find it out.

Moreover, you should take some steps to prevent users from getting too much emails. You should mark them as sent, so they don't receive double posts if you accidentally start the script twice.

Other than that, you should note that php's mail function is inherently not optimized at all. You could try some libraries, like phpmimemessage or any other, which will allow you do to some caching, for example, among many other features.

Palantir
Omg, I didnt know that. So, you normally use "phpmimemessage" to send out 10k++ emails? Which library you are using?
bbtang
I have done something much more complex, but yes, I was using this library to do mass mailing (newsletters). Mimemessage is quite old now, there are better libraries now, see other answers, or google for them. My script was running in the background from CLI however, without time limitations.
Palantir
+4  A: 

Please be aware of this note from the mail documentation:

Note: It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Greg
What library do you use for sending blast email? Pear:: mail?? I am going to study that stuff. Thanks
bbtang
use pear::Mail_Queue, not mail
Peter Parker
A: 

You can use pear::Mail_Queue http://pear.php.net/package/Mail_Queue/

The link is not working, do not know why, but the URL is correct it is something about the underscore sign.. copy and paste it or seach on google/pear website!

It will really do a good job.

Peter Parker
A: 

You should build a queue of emails sent/failed, so you can try to resend failed attempts and avoid re-sending emails if something should go wrong.

Do not create a loop that tries to send 10k emails via mail()

Also, the most likely limit you'll hit will be that of the mail server of your ISP or host.

Joel L
A: 

You may also want to look at setting up a "real" mailing list tool, such as mailman, or at least using alias groups (if possible).

Also, see the related questions on serverfault: http://serverfault.com/questions/67154/sending-an-email-to-about-10k-users-not-spam, where PHPlist is mentioned, along with others. And here - http://serverfault.com/questions/68357/whats-the-best-way-to-send-bulk-email.

warren