I have a following PHP mail sending script which keeps getting failure when accessing via browser.
<?php
$email = "mail@example.com";
$from = "user@example1.com";
if(!mail($email, 'Test subject', 'TestMsg', 'From: '. $from . "\r\n")) {
echo "FAILURE";
}
else {
echo "SUCCESS";
}
?>
I cannot find any coding issues in the script file, however php mail function is not working.
Solution:In order to sort out this issue, please go through the following test cases:
- Test 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
That's it..
--