The WordPress Lost Password Email
We’ve all done it. Not being able to remember passwords is one of the most annoying things about having so many website accounts across the internet. Fortunately, browsers nowadays let you save usernames and passwords for most websites so you don’t have to worry about losing login information that much. However, it does still happen. If you allow user registration on your WordPress site, users will inevitably need to reset their password at some point.
WordPress provides a default password-reset process that involves the user entering their username or email into a form. Once the form is submitted, WordPress sends an email to the user with that username/password that contains a link to reset their password. Once reset, the user can log in using their new password. The thing is that the canned email for this purpose is rather plain. The bright side, though, is that, like most things, WordPress gives us a way to customize this email. The code below does the following:
- Changes the “From” email address. This would be the email any reply is sent to.
- Changes the “From” name. This shows the recipient who the email is from.
- Changes the email subject.
- Changes the content type of the email to HTML so we can use markup within the message. Before, it was a plain-text message.
- Creates a custom message to use in the email body. This process involves assembling a URL with appropriate query arguments so WordPress can do the password reset, and adding a custom message containing that link to reset the password. The only part you’ll change is the message at the bottom (leave the