PHP mail() function returns true, but doesn't send mail

28,941

Solution 1

To send an email you need a SMTP server (local or remote). Actually your mail function just passes the mail to your SMTP server and is this one which really send your email.

In your php.ini appears this line

sendmail_path = /usr/sbin/sendmail -t -i

You should be aware if you use that configuration parameter (from manual):

If set, smtp, smtp_port and sendmail_from are ignored and the specified command is executed.

But the most important thing here is you just uninstall sendmail so you can expect your mail goes nowhere. I know sendmail was giving you some problems, possibly configuration problems, but now your php.ini configuration is wrong.

How to solve it?

  • Start removing the sendmail_path parameter from the php.ini.

  • Install a simple to configure SMTP server like postfix.

  • Verify postfix is listening at port 22:

netstat -lnt

  • Try to send a mail from your php mail() function

  • Verify your mail has been sent correctly (check your /var/log/mail.log or /var/log/mail/mail.log files)

  • You also can verify the mail is not in the postfix queue:

postqueue -f

Solution 2

i had a similar problem to this; both mail() and wp_mail() functions were returning TRUE, but no email was being sent to my [email protected] Email account.

It turns out that Yahoo was blocking these emails as spam. I did not have captcha implemented on my form, and therefore many spam emails were being sent to yahoo which is why they blocked the emails. Emails were sent successfully, but Yahoo was marking them as spam.

make sure this is not the problem in your case.

Share:
28,941
Florian
Author by

Florian

Updated on July 05, 2022

Comments

  • Florian
    Florian almost 2 years

    I know that this question was asked before.

    When I call the PHP mail() function, it returns true.

    I checked my php.ini (I'v running CentOS):

    SMTP = localhost
    smtp_port = 25
    sendmail_path = /usr/sbin/sendmail -t -i
    mail.add_x_header = On
    

    I read in a forum that I have to install sendmail. So I installed it. Now sites with a mail() function doesn't load anymore. So I removed sendmail, and the mail() function returns true again, but doesn't send the mail.

    Any idea?