PHP mail function with postfix

I recently modified a web server to run Postfix instead of sendmail as it’s main MTA. The result was fairly pleasing and a Postfix/Imap/Webmail implementation meant my client was able to pick up and manage mail while travelling. One problem encountered however was the mail server was also a web server. Any time emails were sent using online forms, the resulting mail looked something like the following…

: No recipients specified
Reporting-MTA: dns; mail.threerock.com
X-Postfix-Queue-ID: 93E255C4E41
X-Postfix-Sender: rfc822; apache@threerock.com
Arrival-Date: Wed, 6 Sep 2006 08:26:14 +1000 (EST)
Final-Recipient: rfc822; unknown
Action: failed
Status: 5.0.0
Diagnostic-Code: X-Postfix; No recipients specified
Received: by mail.threerock.com (Postfix, from userid 76)
id 93E255C4D4; Wed, 6 Sep 2006 08:26:14 +1000 (EST)
To: admin@threerock.com
Subject: Threerock Support – Report a Bug
From: “peter mac”

Reply-To: admin@threerock.com
Message-Id: 20060905222614.93E255C4D4@mail.threerock.com
Date: Wed, 6 Sep 2006 08:26:14 +1000 (EST)

After a bit of research and many different opinions from online groups, the fix turned out to be a simple change to the php.ini file (located in this case at /etc/php.ini)The change is as follows:look for the section [mail function] and create (if it doesn’t already exist) a key

sendmail_path = /usr/sbin/sendmail -t -i -f someone@yourdomain.com

Firstly check the path to your sendmail executable by typing

$ which sendmail

Secondly enter a valid username/domainname. This is the user the email will appear to come from. Examples are support@yourdomain.com, admin@yourdomain.com etc.

After saving your php.ini file, you will have to restart your httpd process.

$ /etc/rc.d/init.d/httpd restart

  • Share/Bookmark

One Response to “PHP mail function with postfix”

  1. Kynan Stewart Hughes » Blog Archive » PHP mail() not working? Set the sendmail_path -f in the php.ini file @ November 28th, 2008