Where to check if PHP mail() function is not working

Lots of time we find php mail() function is not working. In some cases, the email is not sent even the function returns true. Following are the points you may check while debugging:

  1. First check if the sendmail_path variable is set properly. You can see it from echo – ing phpinfo() in a page. The typical value is /usr/sbin/sendmail -t -i
  2. If you are sending extra headers in the 4th parameter of the function, try to remove it and send. It is a very common scenario to have incorrect header in the mail function.
  3. Check if you have a spam filter installed in your server which is blocking your email.
  4. If you have access check your mail log file to see if the email is blocked by the mail server or have not reached the server yet. If there is no entry of your email in the log, it means you have problem in your php code or php configuration. If it is in the log, you can see why it was not delivered.
    The typical path to mail log file is /var/log/maillog

If still you can’t find any problem, contact your host.
For sending email, I always prefer the old and great phpmailer class. The ultimate answer to all your php emailing issues. You can also try pear Mail package.


  1. #1 by Asif on July 27, 2009 - 8:32 am

    Helped me, thanks

  2. #2 by Imran on July 27, 2009 - 8:34 am

    Good to know that, keep coming.

  3. #3 by vivek on February 20, 2013 - 7:11 pm


  4. #4 by vivek on February 20, 2013 - 7:12 pm


  5. #5 by Nail Technician Spain on March 22, 2013 - 8:14 am

    We had a problem with sending mail using original contact.php in template we bought. After using our old script it simply worked. As far as I know the older script uses php mail() as well. Also checked settings in phpinfo() on the hosting server and everything looks good in there.
    Weird is that nobody else seems to complain about the script that comes with the template…

  6. #6 by Thabag on April 24, 2013 - 1:38 pm

    I am trying to sent an email from my PHP application from my MS Exchange mail account, everything seems well but my emails are not arriving.
    When i look at the error log file from xammp/sendmail
    i get this “13/04/24 09:32:06 : Connection Closed Gracefully.
    13/04/24 09:33:26 : Connection Closed Gracefully.
    13/04/24 09:34:33 : Connection Closed Gracefully.”

    But no mail is reaching the destination.

    Please help.

  7. #7 by Nat on April 24, 2014 - 4:24 am

    We have this problem, phpinfo() seems ok, mail() returns true but no email recieved. I’m pulling my hair..

  8. #8 by Mukesh on November 20, 2014 - 4:38 pm

    phpinfo is disabled now how to check mail() is enabled or not?

Comments are closed.