-   Linux - Server (
-   -   Delay in sending mail from php (

abhihebbar 11-23-2011 06:58 AM

Delay in sending mail from php
I have a strange issue.

The mails sent by php mail() function are not sent instantaneously.
PHP Code:

$Name "Da Duder"//senders name
$email ""//senders e-mail adress
$recipient ""//recipient
$mail_body "The text for the mail..."//mail body
$subject "Subject for reviever"//subject


This code prints out "Success", however the mail is not sent. It takes a long time before it appears in the inbox. If I restart the sendmail

service sendmail restart
I get all the pending emails.

However if i send email from command line

echo "Subject: test" | sendmail -v
the mail is sent out instantaneously.

The contents of the mail log when a mail is sent from php

Nov 23 07:50:53 hostname sendmail[9658]: pANCorMN009658: from=apache, size=121, class=0, nrcpts=1, msgid=<201111231250.pANCorMN009658@hostname>, relay=apache@localhost
Nov 23 07:50:53 hostname sendmail[9658]: pANCorMN009658:, delay=00:00:00, mailer=esmtp, pri=30121, dsn=4.4.3, stat=queued

however the mail queue is empty as displyed by

sendmail -bp
I get this response for the above command

/var/spool/mqueue is empty
                Total requests: 0

All the emails that are pending will be sent at once.

Any clues?

Thanks in advance

angel115 11-23-2011 08:34 AM

Do you have the same issue with all destination MTA or only one of them? (what about a test on a yahoo or google email address?)
Did you check the log the the MTA that is is charge of receiving the mail? (if you own it)

Make sure that the time are sync via NTP and compare the date/time of both logs.

Maybe it's the remote MTA which delaying the delivery.

Best regards,

lrtward 11-23-2011 08:58 AM

When a program submits a message to the system, the message goes into /var/spool/clientmqueue. At regular intervals, the Queue runner moves the messages from clientmqueue into mqueue. This is probably what's causing your delay. You don't see it when you run sendmail -v because sendmail from the command line will submit messages directly to /var/spool/mqueue.

You can configure the frequency with which the Queue runner processes clientmqueue by editing /etc/sysconfig/sendmail.
You probably have

Set this to something a bit shorter if you want the Queue runner to process messages more quickly. But, be aware that if your server processes LOTS of messages then setting the interval to a "too short" value will make things worse. It is possible to set it short enough (1m, 5m) so that one Queue runner has not yet finished processing clientmqueue when another one kicks off. This can use up more system resources and actually slow things down overall. So set it to an interval that's acceptably short, yet which will not cause multiple Queue runners to process clientmqueue at the same time.

abhihebbar 11-23-2011 09:15 AM

Thanks a lot.
we had QUEUE=1h in /etc/sysconfig/sendmail

I changed it to 1m and the issue is resolved.

However, we have another server, which has QUEUE=1h. But still it sends out emails instantaneously from php.

Any ideas on this? How could this happen?

lrtward 11-23-2011 09:32 AM

1m is almost certainly too fast.
You are going to end up with problems when you get a dozen or so messages in clientmqueue and the Queue runner cannot process them in under a minute.

Regarding why one server sends emails instantaneously and the other does not, I'd compare the /etc/sysconfig/sendmail files of the two servers and if you find no differences there, compare /etc/mail/ between the two servers.

All times are GMT -5. The time now is 01:29 AM.