PHP email not sending

From Hostek.com Wiki
Jump to: navigation, search

Testing the PHP mail function

To test if the PHP mail function is working, save and run the following script.

<?php
$message = "This is just a test. Please disregard.";

if(mail('youremail@domain.com', 'PHP Mail Test', $message)){
        echo "sent";
}else{
        echo "failed";
}

?>

If it fails, then there is a problem with PHP passing email messages to sendmail.

Troubleshooting

Check the Apache error log file: /usr/local/apache/logs/error_log

If you see an error message like:
sendmail: Not running with correct effective GID.  Is sendmail binary setgid mailtrap?

To resolve this issue perform the following:

  1. chown root:mailtrap /usr/sbin/sendmail
  2. chmod 2755 /usr/sbin/sendmail