0

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('[email protected]', 'Subject', 'Message', 'From: localhost <[email protected]>') 

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 mx01.1and1.com[74.208.5.4]:25: Connection timed out
Nov  7 00:37:33 john-laptop postfix/smtp[29133]: connect to mx00.1and1.com[74.208.5.3]:25: Connection timed out
Nov  7 00:37:33 john-laptop postfix/smtp[29133]: BB7E14F00AD: to=<[email protected]>, relay=none, delay=63, delays=0.02/0.01/63/0, dsn=4.4.1, status=deferred (connect to mx00.1and1.com[74.208.5.3]:25: Connection timed out)

hmm...

4 Answers 4

4

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:

5

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 gromit.brassy.net ESMTP Postfix (Ubuntu)

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

$ sudo grep [email protected] /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=<[email protected]>, relay=mx.hotmail.com[1.2.3.4]: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.

1
  • This is very informative. It appears my Connection to hotmail is timing out. I'll add the details to the details of this question. Nov 7, 2009 at 5:42
1

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

0

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.

HTH.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .