I have an Ubuntu server with php and sendmail.

When I use PHP to send an email via sendmail the mail just sits in the sendmail queue forever and never gets sent. Even if I force flush it it still sits in the queue.

What could the cause of this be and how can I fix it?


EDIT: The output of "cat /var/spool/mqueue/qfn82FuSu3009905" is:

MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
$_localhost []
MDeferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.
rRFC822; user@gmail.com
H?P?Return-Path: <g>
H??Received: from world0.com (localhost [])
    by world0.com (8.14.3/8.14.3/Debian-6) with ESMTP id n82FuSu3009905
    for <user@gmail.com>; Wed, 2 Sep 2009 08:56:28 -0700
H?x?Full-Name: www-data
H??Received: (from www-data@localhost)
    by world0.com (8.14.3/8.14.3/Submit) id n82FuR5T009904;
    Wed, 2 Sep 2009 08:56:27 -0700
H??Date: Wed, 2 Sep 2009 08:56:27 -0700
H??Message-Id: <200909021556.n82FuR5T009904@world0.com>
H??To: user@gmail.com
H??Subject: Website feedback form
H??MIME=Version: 1.0
H??Content-type: text/html; charset=iso-8859-1
H??From: dude@domain.com

I do not see where anything is going wrong.


Well, I can ping the server but not talk to it over telnet, how could that be? I have no firewall running.

root@world0:~# telnet alt4.gmail-smtp-in.l.google.com 25
telnet: Unable to connect to remote host: Connection timed out
root@world0:~# ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=241 time=167 ms
64 bytes from icmp_seq=2 ttl=241 time=171 ms
64 bytes from icmp_seq=3 ttl=241 time=169 ms
64 bytes from icmp_seq=4 ttl=241 time=222 ms
--- ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3015ms
rtt min/avg/max/mdev = 167.840/182.722/222.589/23.055 ms
  • What does 'mailq' report? – Joe H. Sep 2 '09 at 16:28
  • mailq displayed the sendmail queue, currently containing 7 messages. – lanrat Sep 2 '09 at 22:24
  • I'm going to assume this means that it's not reporting an errors for the messages, like the other Joe showed in his much more detailed example. Which means there's one other possibility -- sendmail's not even trying to deliver the message. If sendmail had been working, and now it's not, the most common situation I've seen is that the load on the system's gotten high enough that sendmail skips its processing. – Joe H. Sep 3 '09 at 13:37
up vote 2 down vote accepted

I found the solution.

My ISP started blocking port 25 by default to stop spammers. A quick call to them opened the port back up and all mail started flowing.

Thank you Joe for your help.

To find out more about the disposition of a message, try this:


You'll see lots of lines like this:

n812uLGQ001861 12089700 Mon Aug 31 19:56 <******@*****.org>
                 (Deferred: Connection timed out with c.mx.mail.yahoo.com.)
n82FR6a3019167 22388400 Wed Sep  2 08:27 <******@*****.net>
                 (reply: read error from g.mx.mail.yahoo.com.)

where n82FR6a3019167 is the message ID

ls -al /var/spool/mqueue/*<message ID>

Try looking at those files (they're just text files), particularly the one named qn82FR6a3019167 (or whatever your message ID number is. Note: the 'q' before the message ID. You should be able to determine the status of the message, which will hopefully help determine what isn't working properly.

cat /var/spool/mqueue/qn82FR6a3019167

If that doesn't help, you may need to look at the smart relay setting in sendmail.cf. Your PHP server might need to relay mail out through a Smart Relay host.

Next, I would try a manual SMTP session from your PHP server to the Google mail server.

telnet alt4.gmail-smtp-in.l.google.com 25

Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP p9si790839fkb.7

helo <yourhostname>
250 mx.google.com at your service

mail from:<youremail@youraddress.com>
250 2.1.0 OK p9si740839fkb.7

rcpt to:<whoever@gmail.com>
250 2.1.5 OK p9si740839fkb.7

354  Go ahead h2si759562fkh.29
Subject: This is a test

250 2.0.0 OK 1251933071 h2si759562fkh.29

221 2.0.0 closing connection h2si759562fkh.29

Connection closed by foreign host.

This will hopefully tell you if your IP address is being blocked, or if some SPF (Sender Policy Framework) problem exists, or if you have DNS name mismatches that may be causing your email to be denied or deferred.

I presume you truncated the listing of the details in your reply. Your system really should have a valid hostname with reverse DNS entries for that hostname.

Also, check your /etc/hosts file to ensure that your IP address is listed correctly there. It's pretty common to have hostname mismatches be a problem when relaying email to the internet (at least, in my experience).

Something like:

# Do not remove the following line, or various programs
# that require network functionality will fail.        localhost.localdomain localhost
xxx.xxx.xxx.xxx  yourhostname.yourdomain.com yourhostname
  • Thanks, you can see the output of one of the queue files in my edit. I don't seem to see anything wrong with it. – lanrat Sep 2 '09 at 22:31

Look at the lines that say Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com. They tell you that your server was able to resolve an MX record for gmail.com, but it couldn't connect to the remote server. What happens when you telnet to port 25 on that host from the mail server? You should see something like this (note that I typed "quit"):

crunch:/Users/gerald$ telnet alt4.gmail-smtp-in.l.google.com 25
Connected to alt4.gmail-smtp-in.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP d4si791296fga.25
221 2.0.0 closing connection d4si791296fga.25
Connection closed by foreign host.

Do you have any firewall rules in place that would block outbound connections on port 25?

First check the message in the queue and the error log (/var/log/mail.err) Then in order to force deletion, you can do (even though it's in case of it's really stuck )

rm -rf /var/spool/mqueue/*
  • 2
    WARNING This will delete all mail in the queue. You might want to move that mail to a safe location instead of deleting it. – Joe Sep 2 '09 at 16:43
  • var/log/mail.err is empty. – lanrat Sep 2 '09 at 22:29
  • Yes it will purge the queue. So if it's empty, it means there is no error. Maybe sendmail is not right configured. Do you use a smtp gateweay (another smtp server that will handle your messages) or does sendmail send mails by itself ? – Razique Sep 3 '09 at 7:09

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.