Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Enable sending mail with PHP via postfix UNIX
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...]
    •    
  • Currently 3.75 / 5
  You rated: 4 / 5 (4 votes cast)
 
[38,205 views]  

Enable sending mail with PHP via postfix | 4 comments | Create New Account
Click here to return to the 'Enable sending mail with PHP via postfix' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Enable sending mail with PHP via postfix
Authored by: vocaro on Jul 29, '04 03:14:23PM
Postfix uses the RendezVous (nee OpenTalk)

Actually, it's:

OpenTalk (nee Rendezvous).

Trevor



[ Reply to This | # ]
Enable sending mail with PHP via postfix
Authored by: bjackson on Jul 29, '04 04:38:50PM

Another thing to be cognizant of is that alot of mail servers will reject mail if the forward and reverse DNS don't match - so if you're using NAT and don't control your own rDNS you may still be rejected. You can use a dynamic DNS service to get around this - just be sure the rDNS matches your host name.

FWIW

Brian

---
--
Brian Jackson
b.k.jackson@mac.com
http://www.brian-jackson.net



[ Reply to This | # ]
Enable sending mail with PHP via postfix
Authored by: webbix on Jul 29, '04 05:39:02PM

Not really the topic of the hint but some caveats with localhost mail servers

Even with DNS you may get a rejection if recipient servers are using an RBL that blanket rejects IP ranges which are considered dynamic. I had previously setup postfix to use one of my domains anyway as it is convenient to send directly from my Powerbook. My home cable provider is IP range is listed in SORBS. Even though I have a 'static' IP (almost a year) and a DNS that resloves AND no open relay listing I occasionally get rejections.



[ Reply to This | # ]
Enable sending mail with PHP via postfix
Authored by: kfaulhaber on Aug 01, '04 09:21:55PM

I have been using postfix on my powerbook for a while now to avoid having to change the SMTP setting on multiple accounts. Having a valid domain name for your machine is not a guarantee for delivery, unless your ISP specifically allows you to run a server. If your machine does not move very often, your best bet is to have postfix relay mail through your ISP's SMTP server.



[ Reply to This | # ]