HostOnNet Blog

CentOS 7 PHP can’t sent email using mail function

Looking for Linux Server Admin or WordPress Expert? We can help.

On CentOS 7 server, PHP mail() function did not sent email. It always returned false.

I used following test script to verify mail is working

[root@server1 ~]# cat /var/www/html/1.php 
<?php

$result = mail("[email protected]","testing","testing");


var_dump($result);

echo "mail sent at " . time();
[root@server1 ~]# 

I checked the mails server log, found following error message

[root@server1 ~]# tail /var/log/maillog 
Oct  3 02:38:01 server1 postfix/postfix-script[28680]: starting the Postfix mail system
Oct  3 02:38:01 server1 postfix/master[28682]: daemon started -- version 2.10.1, configuration /etc/postfix
Oct  3 15:50:04 server1 postfix/sendmail[1515]: fatal: Recipient addresses must be specified on the command line or via the -t option
Oct  3 15:50:25 server1 postfix/sendmail[1522]: fatal: Recipient addresses must be specified on the command line or via the -t option
Oct  3 15:50:50 server1 postfix/sendmail[1570]: fatal: Recipient addresses must be specified on the command line or via the -t option
[root@server1 ~]#

Problem fixed by adding proper sentmail path in php.ini

sendmail_path = /usr/sbin/sendmail -t -i

Here is config from the server.

[root@server1 ~]# cat /etc/php.ini | grep sendmail
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; 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
; to the sendmail binary. These parameters will always replace the value of
[root@server1 ~]# 

Posted in CentOS

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.