Some WordPress installations stubbornly refuse requests for a password reset link, showing the user this error message instead:
The email could not be sent. Possible reason: your host may have disabled the mail() function.
WordPress’ error massage is anything but insightful. The underlying cause usually involves SELinux. Let us introduce you to an easy fix that does not involve plug-ins or external email services. Buckle up.
Before you embark on your mail configuration, remember to grant yourself root privileges:
sudo su
Step 1. Diagnostics (in case this is something entirely different)
In order to test your server without writing code, install mailx:
yum install mailx
To test outgoing mail, use this command after installtion:
echo testing | mail -s SomeTestSubject your.external@emailaddress.tld
Watch for errors:
tail /var/log/maillog
In order for SELinux to quit blocking access to resources, use this command to switch SELinux to permissive mode (in other words, deactivate the enforcing mode) and repeat the test:
setenforce 0
If you are still getting errors with SELinux in the permissive mode, perform the obvious fixes.
Step 2. Perform any obvious fixes
Any number of errors could show up in the output. You could, for example, see this:
postfix/local[28021]: warning: maildir access problem for UID/GID=0/0: create maildir file /root/Maildir/tmp/1455463988.P28021.ip-12-34-45-67.ec2.internal: Permission denied
One other thing: users of Postfix, don’t change the sendmail path in php.ini to the Postfix path, your mail agent will be jsut fine without you meddling with this setting, so don’t touch this line!
This one is easy. Create the mail directory for user root:
mkdir /root/Maildir/
and you won’t see this error again.
Step 3. Request another password reset link from WordPress
In your web browser, request another password reset link from your WordPress installation. You should see the success message:
Check your email for the confirmation link.
Step 4. Verify that your web server has the permission to send emails
What happens when a user requests a WordPress password reset is directed by the web server (such as Apache or NGINX, whichever is running on your system). Your web server needs a permission to perform this operation. Verify if this is the case:
sestatus -b | grep -i sendmail
The output could look something like this:
gitosis_can_sendmail off httpd_can_sendmail off logging_syslogd_can_sendmail off
Step 5. Grant the web server permission to send mail
Allow the web server to send outgoing mail:
setsebool -P httpd_can_sendmail 1
As a result, the command:
sestatus -b | grep -i sendmail
should deliver this output:
gitosis_can_sendmail off httpd_can_sendmail on logging_syslogd_can_sendmail off
Now feel free to activate the enforcing mode in SELinux:
setenforce 1
and verify that WordPress sends. You should receive the now-familiar message “Check your email for the confirmation link.”
Leave a Reply