Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 11-23-2011, 06:58 AM   #1
LQ Newbie
Registered: Sep 2008
Location: India
Distribution: Ubuntu 12.10
Posts: 12

Rep: Reputation: 0
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

Last edited by abhihebbar; 11-23-2011 at 07:19 AM. Reason: Additional information
Old 11-23-2011, 08:34 AM   #2
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 536

Rep: Reputation: 79
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,
Old 11-23-2011, 08:58 AM   #3
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
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.
1 members found this post helpful.
Old 11-23-2011, 09:15 AM   #4
LQ Newbie
Registered: Sep 2008
Location: India
Distribution: Ubuntu 12.10
Posts: 12

Original Poster
Rep: Reputation: 0
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?
Old 11-23-2011, 09:32 AM   #5
Registered: Feb 2011
Distribution: CentOS, Ubuntu
Posts: 97

Rep: Reputation: 9
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.


php, sendmail

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending E-Mail From a Different Server Using PHP stevec Programming 6 08-02-2011 12:53 PM
sending mail in php to Israel mail servers Four Programming 4 10-23-2009 10:37 AM
PHP mail() sending as apache@ipaddress DukeLeto Linux - Software 1 04-13-2007 10:24 PM
Sending mail with PHP and sendmail. davemar Linux - General 10 06-11-2004 04:48 PM
Form not sending mail using includes... PHP cadkins Programming 3 04-27-2004 06:38 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration