Home » Php » email – Is there a limit when using php mail function?

email – Is there a limit when using php mail function?

Posted by: admin July 12, 2020 Leave a comment


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)){
        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?

How to&Answers:

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.


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.


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.


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: https://serverfault.com/questions/67154/sending-an-email-to-about-10k-users-not-spam, where PHPlist is mentioned, along with others. And here – https://serverfault.com/questions/68357/whats-the-best-way-to-send-bulk-email.


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

It will really do a good job.