Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble getting the PHP's mail() function to work on my localhost laptop computer. I'm using Ubuntu 9.04 and I connect to a wireless network at home for internet. I ran the following command in terminal:

sudo apt-get install postfix

Everything looked fine. I didn't see any errors. When I ran the

mail('', 'Subject', 'Message', 'From: localhost <>')

in PHP, the function returned true. But even though it returned true, I never got the emails in my hotmail account.

Did I miss a step?

I looked at my mail.log, and it says my connection is timed out:

Nov  7 00:36:30 john-laptop postfix/pickup[28698]: BB7E14F00AD: uid=33 from=<www-data>
Nov  7 00:36:30 john-laptop postfix/cleanup[29131]: BB7E14F00AD: message-id=<20091107053630.BB7E14F00AD@john-laptop>
Nov  7 00:36:30 john-laptop postfix/qmgr[4088]: BB7E14F00AD: from=<www-data@john-laptop>, size=316, nrcpt=1 (queue active)
Nov  7 00:37:03 john-laptop postfix/smtp[29133]: connect to[]:25: Connection timed out
Nov  7 00:37:33 john-laptop postfix/smtp[29133]: connect to[]:25: Connection timed out
Nov  7 00:37:33 john-laptop postfix/smtp[29133]: BB7E14F00AD: to=<>, relay=none, delay=63, delays=0.02/0.01/63/0, dsn=4.4.1, status=deferred (connect to[]:25: Connection timed out)


share|improve this question
up vote 3 down vote accepted

While you can install a SMTP server on your workstation, it is very likely that you message will be blocked at various locations.

Many ISPs block outgoing SMTP from residential accounts to combat spam.

Many email providers keep lists of IP addresses associated with residential broadband access and block incoming mail, or move it immediately to a junk/spam folder.

It sounds like the messages where accepted by postfix, so you can probably look at the postfix logs and you will see error messages if the message could not be delivered. These error messages will help you figure out where you are being blocked.

But as I mentioned above, you probably won't be able to fix whatever is blocking you. You probably should find a mail provider with an SMTP server that you can connect to and use to send your messages.

See these related questions:

share|improve this answer

OK, people are guessing here, I think I'd prefer to go down the troubleshooting and diagnostic route before actually giving you an answer. Their answers are very valid, but nonethehless, we don't even know if your mail is being relayed by your local MTA.

OK, first thing is first, you've installed Postfix... is it running?

$ sudo /etc/init.d/postfix status
$ telnet localhost 25

telnetting to localhost on port 25 should give you a banner indicating Postfix is installed like:

220 ESMTP Postfix (Ubuntu)

OK, so you've confirmed Postfix is up and running. Next thing, search your mail.log:

$ sudo grep /var/log/mail.log

(You look like you might be on Ubuntu / Debian, your mail log is normally in /var/log/mail.log on other systems it may be /var/log/maillog. Secondly if you're on Ubuntu, a lot of the time your user account will have access to read the mail.log directly without sudo'ing as you're in the appropiate group)

You should see lines like:

Nov  8 08:37:24 hostname postfix/smtp[7164]: E97DE56A31: to=<>,[]:25, delay=4.2, delays=0.21/0.11/3.8/0.1, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 1D7BF761F3)

So there's a lot of information on that line, but what you want is the postfix queue id to see everything that's happened.

The start of that line contains the time and date, along with the postfix and the PID of the process which logged the line. The next part is the queue id: E97DE56A31

Now this line normally tells you whether your mail was sent, but it's good practice to run through this procedure anyways:

$ sudo grep E97DE56A31 /var/log/mail.log

This should give you the full transcript of your mail.

If in the above scenario you could find nothing of interest in the mail.log file, it looks like your mail was not submitted to Postfix. You need to start checking your php.ini mail settings at that point.

share|improve this answer
This is very informative. It appears my Connection to hotmail is timing out. I'll add the details to the details of this question. – John Nov 7 '09 at 5:42

There could be any number of reasons as the other posters have outlined. First thing I'd do is run the mailq command line application to see if your test messages are sitting about, waiting to be delivered. I'd also be looking in /var/log/mail.log to see what's happened to the emails (just like Zoredache said).

It's quite possible that Hotmail (or wherever the desintation was) just dumped your email. It may well have failed a few basic anti-spam tests (e.g. hostname might not be fully qualified, probably won't match the PTR).

Cheers, jmi

share|improve this answer

If you want to use your localhost as mail server (as you want to test scripts etc) you need to tell you mail server to use your ISP's mail server as a "smarthost". Now "smarthost" is the sendmail term (I do not use postfix) but I am sure there is a postfix equivalent.

What it basically means for each email you send (by whatever means) and your localhost is the mail relay it will use your ISP's mailserver to do the work, by postfix connecting to your ISP's mailserver instead directly to e.g. hotmail.

ISP's block (on your connection) port 25, which is the mail port, to combat spam, so you cant send directly but you can send indirectly using your ISP's mail server.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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