Error:
I have a following PHP mail sending script which keeps getting 'FAILURE' when accessing via browser.
========================================================
========================================================
<?php
$email = "mail@yourdomain.com";
$from = "admin@from.com";
if(!mail($email, 'Test subject', 'message', 'From: '. $from . "\r\n")) {
echo "FAILURE";
}
else {
echo "SUCCESS";
}
?>
php mail function is not working in the server. There is no coding issues in the script file.
Solution:
In order to sort out this issue, please go through the following checks.
Check if php mail function is disabled in php.ini
root@server [~]# cat /usr/local/lib/php.ini | grep disable_functions
disable_functions = "mail"
If it is disabled, remove the entry of 'mail' from php.ini from the line, "disable_functions =". Then,
# /etc/init.d/httpd restart
If you are still having problem, try the following test. Let your mail script is mail.php. Then run the following command.
root@server [~]# php mail.php
sendmail: Not running with correct effective GID. Is sendmail binary setgid mailtrap?
sendmail: Not running with correct effective GID. Is sendmail binary setgid mailtrap?
root@server [~]#
If you are getting an error as like above, you can do the following commands to fix this error.
root@server [~]# which sendmail
/usr/sbin/sendmail
root@server [~]# chown root:mailtrap /usr/sbin/sendmail
root@server [~]# chmod 2755 /usr/sbin/sendmail