Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: PHP Mail function fails sending mails  (Read 6594 times)

0 Members and 1 Guest are viewing this topic.

lijeshk

  • Guest
PHP Mail function fails sending mails
« on: November 09, 2013, 11:11:59 am »
Quote
I have a following PHP mail sending script which keeps getting failure when accessing via browser.

Code: [Select]
<?php
$email 
"mail@example.com";
$from "user@example1.com";
 
if(!
mail($email'Test subject''TestMsg''From: '$from "\r\n")) {
    echo 
"FAILURE";
}
else {
    echo 
"SUCCESS";
}
?>

Quote
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

Code: [Select]
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,
Code: [Select]
# /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

Code: [Select]
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:

Code: [Select]
root@server [~]# which sendmail
/usr/sbin/sendmail

Code: [Select]
root@server [~]# chown root:mailtrap /usr/sbin/sendmail
root@server [~]# chmod 2755 /usr/sbin/sendmail

That's it..

--
« Last Edit: November 09, 2013, 02:20:09 pm by lijeshk »