Enable sending mail with PHP via postfix

Jul 29, '04 09:53:00AM

Contributed by: androse

So, with some help, you've enabled Postfix on your machine. You've added 127.0.0.1 to your list of SMTP servers in Mail, and sending mail works. Now if you want to send email by running local PHP scripts that use the mail() function, you will probably see that your messages are being systematically rejected by the server of the recipient. In your /var/log/maillog file, you'll probably get lines like this (broken up for easier readability here):

Jul 27 20:21:34 myMac postfix/smtp[10888]: CED002D04DD: to=,
  relay=mydomain.com[xxx.xxx.xxx.xxx], delay=1036, status=deferred
  (lost connection with mydomain.com[xxx.xxx.xxx.xxx] while sending
  MAIL FROM)
The problem is that, by default, Postfix uses the RendezVous (nee OpenTalk) .local top level domain, which is, as far as internet hosts go, invalid. Basically, Postfix is trying to send email from www@yourmac.local (www being the user PHP is being executed by, if it's running as an Apache module).

So here's the trick: edit the file /private/etc/postfix/main.cf, and change the myhostname parameter to a valid domain name you control. Then restart Postfix (sudo postfix reload) and you're done. You can now use the mail() function in PHP.

[robg adds: A much older hint discussed PHP and sendmail, but we haven't covered postfix and PHP before, I don't believe...]

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040727144509713