PHP email not sending

From Hostek.com Wiki
Revision as of 16:41, 13 June 2014 by Maxm (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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