LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 11-23-2011, 06:58 AM   #1
abhihebbar
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 "email@adress.com"//senders e-mail adress
$recipient "email@adress.com"//recipient
$mail_body "The text for the mail..."//mail body
$subject "Subject for reviever"//subject

if(mail($recipient$subject$mail_body$header)) 
echo 
"success";
else 
echo 
"Failed"
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
Code:
service sendmail restart
I get all the pending emails.

However if i send email from command line
Code:
echo "Subject: test" | sendmail -v test@example.com
the mail is sent out instantaneously.

The contents of the mail log when a mail is sent from php
Code:
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: to=test@example.com, delay=00:00:00, mailer=esmtp, pri=30121, dsn=4.4.3, stat=queued
however the mail queue is empty as displyed by
Code:
sendmail -bp
I get this response for the above command
Code:
/var/spool/mqueue is empty
		Total requests: 0
Update:
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
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 494

Rep: Reputation: 75
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,
Angel.
 
Old 11-23-2011, 08:58 AM   #3
lrtward
Member
 
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
QUEUE=30m
or
QUEUE=1h

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
abhihebbar
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
lrtward
Member
 
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/sendmail.cf between the two servers.
 
  


Reply

Tags
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


All times are GMT -5. The time now is 06:48 PM.

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