Skip to content
Home » Linux » How To Make PHP Mail Work on Linux

How To Make PHP Mail Work on Linux

In WAMP, you can setup an external SMTP server for PHP to send mail, but in LAMP, it's not the same story. You have to configure it manually to make it functional.

In this post, we introduce some steps to resolve PHP mailing problem. I assumed that you already have the PHP code for testing the mailing function.

Comment out SMTP Entry in php.ini

We should comment out SMTP entry in php.ini, so we searched for an entry called SMTP and comment it out by a semicolon as below:

[root@test ~]# vi /etc/php.ini
...
;SMTP = localhost

Make Sure sendmail has been Installed

We should make sure that sendmail has been installed. If not, please install it.

[root@test ~]# rpm -q sendmail
[root@test ~]# yum install sendmail
...

Restart Server

Restart the server to make sendmail to take over the mailing function.

[root@test ~]# init 6

Check sendmail Status

Check the status of sendmail.

[root@test ~]# service sendmail status
sendmail (pid  2496) is running...
sm-client (pid  2495) is running...

For EL7 or later, you may use this:

[root@test ~]# systemctl status sendmail

It seems functional, we can try to execute the PHP code again, but in fact, it failed.

Check maillog

Check the /var/log/maillog and see what happened.

[root@test ~]# tail -f /var/log/maillog
...
Jan  6 20:38:11 test sendmail[2703]: NOQUEUE: SYSERR(apache): can not chdir(/var/spool/clientmqueue/): Permission denied

There might be sendmail errors NOQUEUE: SYSERR(apache) due to permission issue, we can solve it by turning it ON in SELinux.

Now, it's working.

Leave a Reply

Your email address will not be published. Required fields are marked *