I'm improving PHP mailing list code that uses mail()
in a loop while iterating through all subscribers. The script used to display a "Maximum execution time of 30 seconds exceeded" error which I solved by adding set_time_limit(0);
.
Now there's no error but it took about seven minutes to send 100 messages. What are my options?
Will sending just a single message with all subscribers in BCC help or is it the same "behind the scenes"?
Sending to all as BCC will be a lot faster. The code will execute faster and mail()
will be executed only once.
This is the quick fix, but as mentioned, a large BCC list is a safe road to the spam folder. However, using mail()
is a sure destination to spam too.
If you want to actually improve it, use PHPMailer from SourceForge and send via SMTP (less spam hits) using cron in batches of X emails once.
The PHP docs state:
Note:
It is worth noting that themail()
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 sending large amounts of email, see the
» PEAR::Mail
, and» PEAR::Mail_Queue
packages.