First steps to fixing a non-functioning php mail() function

Want to learn something new? Check out my most recent Egghead course:

Build a Twelve-Factor Node.js App with Docker - WATCH NOW on!

Cheers -Mark

Mon, 09/20/2010 - 00:00

Submitted by markoshust Mon, 09/20/2010 - 00:00

After creating and configuring a new LAMP stack, there are times where the php mail() function will not work. This could cause a lot of headaches, but there are really only a few things to check to save yourself from a bunch of waterworks and lost time.

  1. Make sure php-imap is installed. This is necessary for php to send mail
    yum install php-imap
    service httpd restart
  2. Ensure your machine has a FQDN (fully-qualified domain name). You may query the current hostname using
  3. If you are testing a new domain which is not yet configured on the server, using the default Postfix mail program, add the domain
    nano /etc/postfix/

    Change the myhostname variable to your domain, example:

    myhostname =
  4. Test the mail function using a good sendmail.php script… such as the following:
    PHP Mail() test
    This form will attempt to send a test email. Please enter where this test should be sent to
    Enter an email address:

    \n"; if(mail($mail_to, $mail_subject, $mail_body,$header)) { print "Email sent successfully!"; } else { print "Email did not send"; } } ?>

First, follow the above steps. If those still don’t work, then you need to start digging further…