FIXED: WordPress refuses to send you a Password Reset Link
I ran into an interesting problem today: on a CentOS 6 server a colleague of mine wanted to reset her WordPress password via the handy link provided in the login dialogue. But rather than sending an email, WordPress got back to her with the following error message:
The e-mail could not be sent.
Possible reason: your host may have disabled the mail() function.
Intrigued I had a look at the server. To my surprise sendmail was installed, and emails could be sent from the command line as well as from PHP scripts. But not from WordPress. What was going on?
Examining the logs I came across the following error message:
sendmail: fatal: chdir /var/spool/postfix: Permission denied
followed by a Web Server 500 error caused by the password reset link. Interesting.
Turns out it was an old acquaintance of mine, someone who has been spoiling the broth on many occasions: SELinux.
SELinux can prevent Apache from sending mail when enabled, but lucky for us there’s a quick way to fix this, courtesy of manyon over at the Simple Machines Forum.
To test if SELinux is preventing mail from being sent, try this test from the command line:
It will return with httpd_can_sendmail –> on or off, and if your server is set to the latter then mail can’t be sent.
To change this, execute the following, switching this bool to on:
sudo setsebool -P httpd_can_sendmail 1
Note that this can take a minute or two (literally) because the entire SELinux policy needs to be recompiled. Be patient, your server isn’t hanging.
Once changed, make sure to restart Apache:
service httpd restart
Now WordPress can send the password reset link. #result