Php – Sendmail over SMTP is Throttling My PHP Script… How to make it behave

emailmailing-listPHPsendmail

Here's the situation: I've got a Redhat Linux server with PHP 5.2 and standard sendmail that we're using to send email to a list of 10,000 email addresses. We have a fairly simple script that uses PHPMailer and connects over SMTP to the listening sendmail daemon.

Whenever this script runs, it'll eventually get to the point where it will just start running dirt slow – it'll start off fast, but then slow down to only sending 1 email every few minutes. When I restart the script, it runs fast again for a bit.

Over on the sendmail server, I've added a few settings in the script to attempt to fix the throttling issue:

define(`confMAX_QUEUE_RUN_SIZE',`0')dnl
define(`confBAD_RCPT_THROTTLE', `0')dnl
define(`confCONNECTION_RATE_THROTTLE', `0')dnl

So far, I'm not sure the best way to fix the problem – or to even troubleshoot it. The /var/log/maillog file doesn't really have any useful information in it.

We've got this sendmail instance behind a firewall, so we don't need to worry about security… just open it up and let the mail flow!

Best Answer

You shouldn't be connecting to the remote SMTP by script, but deliver to the localhost using sendmail (or better, postfix). Sendmail should take care of delivering the messages. If you need to make sure all messages go out through a specific gateway machine, configure sendmail with the correct smarthost.

The reason you want to do this is that sending mail is much more complex then you might initially think, and sendmail (or better, postfix) is built to handle all of the gory details like queue management.

As for what's happening on the mail server itself, have you checked the load and other factors on that server? It might be overloaded after you've sent so many messages to it, and is legitimately slow because of it. Check things like 'top', 'netstat -n', etc...