I have a system that sends lots of emails reports ( about 500+ emails per day). I am not a spammer :) It's not really big amount of e-mails, but they are send in a loop and I often get this error "PHP Warning: mail(): Could not execute mail delivery program". I know there is PEAR::Mail_Queue package for this issue. But can you please let me know if that package is really useful thing, or do I need to look for something else. Thanks a lot
sending large amounts of email in a loop
2.2k views Asked by alagar AtThere are 4 answers
You can use PEAR's Mail_Queue package to send mails through an SMTP server directly - also it will work in the background and so won't delay or increase your script execution time.
Another advantage of using the Mail_Queue package is that you can retrieve the esmtp id of each mail sent for logging purposes - I don't know if this is possible with the Zeta Mail component or any other one.
I've developed a number of public-facing, and also intranet only, solutions that use this component and haven't had any major problems with it.
An alternative could also be to send mails through an SMTP server directly. This saves you the round trip of PHP calling sendmail (or whatever MTA is used) "through the shell" in order to deliver the mail. For example the Zeta Mail component allows you to send mails directly through an SMTP server without needing a special extension for this.
"PHP Warning: mail(): Could not execute mail delivery program"
...means exactly what it says on the tin. PHP will just hand the email off to an external program on a Linux/Unix/POSIX system (as defined by sendmail_path in php.ini). And in some cases that is returning an error. It's not a fault within the PHP code.
Unless you've got a really badly configured MTA, then the problem will not be resolved by using an SMTP connection instead.
You need to look at the logs from your MTA to see why its failing to send the mail - or wrap the mail executable in a logging script.
You gotta use sleep() between mails, that solves this.