Actually configure Postfix or Sendmail for PHP mail() is the same. Both of them run the /usr/sbin/sendmail binary. It is quite confusing if we just look at the name of the binary but this is what Postfix did.
For more information, take a look at the Postfix Manual – sendmail.
For the PHP setting, open the /etc/php5/apache2/php.ini and configure the sendmail_path.
php.ini
; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = "/usr/sbin/sendmail -t -i"
Save the file and restart the Apache server.
Try testing the PHP mail() function by the following command. Thanks amitbhatia1. =)
echo testing | mail -s Bla myemail@somewhere.com
If you need to send with attachment. you can refer to this post.
PHP – Send Attachment with PHP mail()
Done =)
Reference: Using the mail() function in php with postfix on linux
I got to say thank you for this post. I have this page bookmarked for me as I always forget where to point the sendmail_path to !!
great website too
Good to know that it helps =)
Pingback: The Dev Pages » Blog Archive » Using the mail() function in php with postfix on linux
like {Linkin’ Earth} (@Linkin_Earth), this post is very helpfull for me, thanks alot anyway
You are welcome. =D
Im grateful for the post.Much thanks again. Fantastic.
Good to know i could help. =)
It’s not working at all… Something wrong with the file?? No ‘Error’ message. What might be the problem??
it’s your postfix/sendmail already working? if not yet, try to setup a relay and make sure it works.
Postfix – Relay via Gmail
I didn’t set up the relay, because I hate gmail and want to close my account. I uninstalled postfix completely and installed it again and configed php.ini. Now mail() function is working. I have a question though.
It works with $headers = ‘From: me@hushmail.me‘; But once I change it to a different address, such as me@gmail.com, (ie., ‘From: me@gmail.com‘;) the mail doesn’t get sent. In the mail.log file I see “Sender address rejected: Domain not found (in reply to MAIL FROM command)).” How can I fix this problem? When I save up enough money I want to build my own website, and I want to use the email address of my site to send and receive mails instead of me@hushmai.me.
I am not familiar with the mail server setting but seems that you need to setup the MX record as well as A record in your domain manager.
The following post may be helpful.
postfix ‘Sender address rejected: Domain not found’ error
Thanks much. It didn’t solve my problem, but I appreciate your quick response!
i am sorry that i couldn’t help.
actually some hosting providers have email service and what you need to do is just setting up the domain for the email service. i think maybe you can seek help from you web hosting service provider.
I made a simple php script to test and is giving this error on my server
server name: Demeter
OS: Linux RedHat
installed: apache + php + Sendmail
sendmail works mada normal email is ok
the problem is to have php that will not and this error:
n 25 12:20:09 demeter sendmail[13202]: NOQUEUE: SYSERR(apache): can not chdir(/var/spool/clientmqueue/): Permission denied
It’s a permission problem. try to change the /var/spool/clientmqueue/ to 770 and add the apache user to the sendmail user group.
Reference: StackOverflow – Ubuntu Jaunty + sendmail + PHP + mail() Premission Errors
Thank you for your help this has fixed my php mail.
You are welcome. =)
Pingback: How To: Nginx, PHP-FPM, MySQL, phpMyAdmin, Postfix on Ubuntu | Deadly Technology
thanks.
You are welcome and thanks for your comment. =)
It worked perfectly. Thanks a lot. Only the last line for checking email should be
echo testing | mail -s Bla myemail@somewhere.com
Thanks for the command. I have updated the post. =D
I can’t seem to get it to work, I just want to send mail, my server has internet access but my site is lan only as my isp blocks port-forwarding, but I don’t think that sould matter much to send mail any help appriciated.
The error log
Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt1.gmail-smtp-in.l.google.com[74.125.137.27]:25: Connection timed out
Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt1.gmail-smtp-in.l.google.com[2607:f8b0:400e:c01::1a]:25: Network is unreachable
Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt2.gmail-smtp-in.l.google.com[2607:f8b0:4002:c04::1a]:25: Network is unreachable
Feb 11 07:46:32 h4x0r-Linux postfix/smtp[13557]: 821ADAB1BA: to=, relay=none, delay=21372, delays=21311/0.08/60/0,
Try setting the inet_protocols in the main.cf as follow and restart postfix.
Reference: [SOLVED] connect to gmail-smtp-in.l.google.com[...]:25: Network is unreachable