I recently implemented a comment area on my website and tried to get the email notification to work. It doesn’t seem to want to send email notifications when new comments are made.
Just to see if PHP can send emails, I tried to reset the password (because you’ll get a new password via mail), and I got the message:
The e-mail could not be sent. Possible reason: your host may have disabled the mail() function
I’ve checked the checkboxes in Settings -> Discussion, and the email is valid, so it’s not a setting issue. I tried to create a PHP file and send using mail()
, and it sent successfully. So there must be something weird going on with WordPress.
Any ideas?
Step by step: First find the file where the error message appear. I use Notepad++ and the CTRL + F command to search in files. It is a good idea to search only the first few words of the error message, because some error messages are combined of different messages.
Your error message appear in
wp-login.php
and holy luck, only there. So let’s have a look why this error could occur.There are two conditions.
$message
have to be true (not an empty string, not false, not null, etc). Andwp_mail()
shouldn’t return false.One line above, there is a filter
$message = apply_filters('retrieve_password_message', $message, $key);
, so it is possible that a plugin (or theme) use this filter and returns a value that is not true (empty string, false, null, etc.).But it is much easier to check if
wp_mail()
is working or not. Write a small plugin to send a test mail to yourself:(This is PHP5.3 code. If you are running PHP5.2, remove the namespace things)
The plugin should send a testmail immediately after activation. If not, calling some backend pages (e.g. dashboard) should do it.
If the testmail does not arrive, then you probably have an issue with
wp_mail()
. So turn on debugging:Put this code into your
wp-config.php
and retry sending yourself a testmail. Now you should get some error messages and they also should be logged intowp-content/debug.log
(The debug log can grow very large if there are more errors caused by plugins and/or themes).At this point, you got good informations if
wp_mail()
fails and if so, why. Ifwp_mail()
work correctly and the testmail arrived, go back to top and find out why$message
is not true.If you have issues with
wp_mail()
, so keep in mind thatwp_mail()
does not use PHPsmail()
function. WordPress use a PHP class (PHPMailer). Maybe you just need a plugin to use SMTP instead of sendmail. Or the problem is located at another place. We don’t know. You have to investigate.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, but 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 has same issue with Ubuntu server on Amazon EC2.I get issue while using reset password link and also other notification email were not working.
So here is solutions which worked for me.Word-press used
wp_mail()
function to send email which needPHPMailer
class which used php mailer stored in/usr/sbin/sendmail
.Use this simple php function first to check php mail
If this is not working then you need to install php mailer.
Use this command to install php mail on Ubuntu server.
Then check word-press email functions.
If the other great answers here don’t help, try this:
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.
I ran into this today; in my case the situation happened because the server’s hosts file has the same domain name of the email address, pointing to localhost. The mx record points to a different server, but the hosts file is overriding DNS and WP is trying to deliver the email locally. Removing the domain from the hosts file and restarting sendmail resolved this issue.
I don’t know whether this is still relevant to you or not, but since there is no answer chosen, I thought let me give it a try once.
Actually, I had faced the exact same problem since my openshift host all of a suddenly gave way today and stopped sending mails. Digging through the code and codex, I came to know about the wp_mail() function and finally google led me here and I saw how it could be overridden.
Building on @Ralf912’s answer, I modified the script a bit so that the code uses sendgrid.com’s web api to send mails instead of wordpress default one (that I presume :
And it worked!
I had the same error, both functions(mail and wp_mail) worked, but I still had this annoying error. The fix was very easy, but it took me few hours to find the reason. So I will share here my solution on the problem which might be (or might not) the same with yours.
I tried mail() function and it worked, but when you test it you don’t specify the last parameter called ‘parameters’ in mail() function. And WP does use it.
So, basically, this parameter (“-fexample@exmaple.com”) with flag “-f” makes mail() function check if the email address “example@exmaple.com” listed in the “trusted emails” list.
So if it doesn’t, it returns false, which makes wp_mail() returns false and leads to the error message.
So, solution is to ask hoster to do this for you, or if you are using cPanel, just add email account for this address and it will automatically will add it into the “trusted list”.
it called -Manage Registered Email-Ids For Sending Mails via Scripts ie.(WordPress)
I had this error for ages and tried so many solutions that didn’t work. I have a custom WordPress install on AWS EC2. First off ensure your AWS SES mail is enabled through support, they must be in the same (or close) region in SES and EC2.
I used Google suite(gsuite) for email for receiving/sending mail.
Make sure the test email sends in AWS SES and Gsuite.
Install the WordPress plugin WP Mail SMTP, use the option “Other SMTP”, grab your SMTP credentials from AWS SES, this is where I got stuck.
You must enable the tick box “SSL” for Encryption, this changes the port to 465 for me. At last my email test sent from Worpdress successfully.
I fixed this issue by changing the “From Email” on my local test environment, by changing it from wordpress@localhost to wordpress@localhost.localdomain, for example using a WordPress plugin like “WP Mail SMTP” and selecting the default PHP mailer instead of using SMTP.
The issue happened even with all other plugins disabled and I did not have this issue in the past. The issue is also not present when using the PHP mail function directly, so maybe it happened because of a recent WordPress change.
I sent and received emails on my local computer using Postfix.