romeldris
By:
romeldris

PHP mail not working but sendmail does

September 22, 2014 3.4k views

Hey guys,

I'm able to send mails through sendmail but I'm unable to send mail with the PHP mail() function. I changed it in the config files as well but it's not being sent. When I type sendmail in the terminal, I'm able to send it. Am I supposed to configure something else to get PHP mail to work?

3 comments
  • Are you getting any errors? Try adding the following line at the top of your php script:

    ini_set('display_errors', 1); error_reporting(-1);
    

    That should make php output all errors to the web browser.

  • Yes I was actually getting some errors and managed to fix them! I can now send emails from the PHP mail function :)

  • Note: some emails sent by php's mail() function may arrive as SPAM to some recipients because their mail servers cant verify the origin of the email. Be sure to have the correct email headers, PTR records, and everything properly set up. My suggestion is that you try and deliver all your email via SMTP.

1 Answer

This question was answered by @kamaln7:

Are you getting any errors? Try adding the following line at the top of your php script:

ini_set('display_errors', 1); error_reporting(-1);

That should make php output all errors to the web browser.

You can see the comment here.

Have another answer? Share your knowledge.