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 🙂
LikeLike
Good to know that it helps =)
LikeLike
like {Linkin’ Earth} (@Linkin_Earth), this post is very helpfull for me, thanks alot anyway
LikeLiked by 1 person
You are welcome. =D
LikeLike
Im grateful for the post.Much thanks again. Fantastic.
LikeLike
Good to know i could help. =)
LikeLike
It’s not working at all… Something wrong with the file?? No ‘Error’ message. What might be the problem??
LikeLiked by 1 person
it’s your postfix/sendmail already working? if not yet, try to setup a relay and make sure it works.
Postfix – Relay via Gmail
LikeLiked by 1 person
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.
LikeLike
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
LikeLike
Thanks much. It didn’t solve my problem, but I appreciate your quick response!
LikeLike
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.
LikeLike
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
LikeLike
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
LikeLike
Thank you for your help this has fixed my php mail.
LikeLike
You are welcome. =)
LikeLike
thanks.
LikeLike
You are welcome and thanks for your comment. =)
LikeLike
It worked perfectly. Thanks a lot. Only the last line for checking email should be
echo testing | mail -s Bla myemail@somewhere.com
LikeLike
Thanks for the command. I have updated the post. =D
LikeLike
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.
LikeLike
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,
LikeLike
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
LikeLike
It’s not working for me either.
Using mail to send like in you example, I only receive a waring message.
WARNING: gnome-keyring:: couldn’t connect to: /tmp/keyring-rgI6w9/pkcs11: file or directory not found
but I don’t think that’s the problem.
My mail.log file:
If you can help me?
LikeLike
sth related the your gnome setting? see if you could find some clues in the post below.
gnome-keyring can’t connect to pkcs11 file
LikeLike
Hey Hi,
postfix mail is working from past few years and suddenly it get stopped. dont know why.i tried to reinstall it. now i can able to send mails over command. But not with php code. but i did try to add this line to php.ini file.(sendmail_path = “/usr/sbin/sendmail -t -i”) and restart the postfix service. Here is the error log. please check and suggest.
Jun 25 07:21:53 j78921 postfix/sendmail[29750]: fatal: Recipient addresses must be specified on the command line or via the -t option
LikeLike
restart apache after updating php.ini. it should works if u have specified the -t parameter.
StackOverflow – PHP mail does not get sent, how do I debug?
LikeLike
I had removed “sendmail” What worked for me was adding “.postfix” to the path. “sendmail_path = “/usr/sbin/sendmail.postfix -t -i”
LikeLiked by 1 person
not sure how it works on your machine but thanks for giving ur solution here. =)
LikeLike
I am looking for a solution to a similar problem for the “Windows host – Debian Virtualbox” bundle.
Unfortunately your solution did not work. Perhaps this is due to the old age of the post.
LikeLike