I’m using Apache 2.2.25 and PHP 5.3.28 in my Windows 8 desktop. Once when I was recovering my wordpress password, I got this error:
The e-mail could not be sent. Possible reason: your host may have disabled the mail() function.
I googled it that how can I enable mail() function, found that I need to configure a mail server with my server. I downloaded hMailServer, but it didn’t work… Please help me how can I enable mail() function? Which mail server will I have to download?
As I posted here:
This is a super annoying error message as it could be many things, and it doesn’t reveal the actual error (which is often silenced in other parts of the code).
This error appears when the
wp_mail()
function returns false, which in turn could happen ifphpmailer->Send()
returns false or raises an exception.How to display warnings from PHP’s
mail()
functionThese are normally silenced by default, and unfortunately WordPress never captures them. To show them, simply remove the
@
signs from@mail(...
inwp-includes/class-phpmailer.php
in themailPassthru()
function:How to hunt down other possible causes:
Add a single line to the bottom of
wp_mail()
in/wp-includes/pluggable.php
:It will dump the full details of where the exception was raised. Unfortunately it sometimes includes this unhelpful exception message: “Could not instantiate mail function“. Yeah thanks WordPress, that’s real helpful.
By looking at the exception you can find the line number of the error, and can hopefully trace it back through the code to find the real cause.
Good luck. Hopefully WordPress improves email error handling at some point in the future.
I encountered this same problem and nothing I could find in any of the suggestions for WordPress solved it for me.
Then I started investigating if it was the PHP installation itself that had disabled the mail function, but none of that worked either. Everything looked like it was configured properly.
All of these problems started for me once I upgraded my server to CentOS 7 which uses SELinux (Security Enhanced Linux) and what I’ve learned in the last couple of weeks with SELinux is that if something isn’t working, but everything looks like it should be working… that means SELinux is silently and secretly blocking you in the background.
And viola.
If you are running and OS that uses SELinux, just execute the following command as root:
setsebool -P httpd_can_sendmail=1
There is a security setting that inherently prevents the webserver from sending email. When you flip that switch and tell SELinux it’s ok for the webserver to send email, everything suddenly works.
it called -Manage Registered Email-Ids For Sending Mails via Scripts(WordPress)