W7Code » PHP » How to create a Forgot Password PHP

Today we will learn how to create a forgot password PHP page. If the user is getting troubles sign in your account, we can send a recovery email to reset and set a new password. After we have created a Login Form, Registration Form in PHP and send a confirmation email to new users confirm their account. Now we need create a password recovery page.


How the user recover password?

If user have forgotten his password, he can:

  • access to recovery password page;
  • enter is email to receive a recovery email with:
    • a link to click and set a new password.
  • when the user click on the link he is redirected to the reset password page;
  • after we reset his password he receive a new email saying that his password has changed.


First we will create the ‘ recovery_page.php ‘ file, where the user can insert his email to receive the recovery email.



Now we need create a new table in our database named ‘ recovery_password ‘. Which will contain the request for a new password. This table will store the username, email, hash ( which is randomly generated) and password_active ( this last is to restrict, the password change only 1 time using the link).



Now we have collected the email, we need to process this information. For this we will add some code to our ‘ connection.php ‘ file which we have create in the previous class. This code will be responsible to send the email with the recovery link:


Now that we have created the system of sending the recovery email, we need create the ‘ change_password.php ‘ file where you can change your password.


Learn to:


Download the Full Project here.

Final Result:

forgot password php forgot password php send emailHave any doubt?Please comment it bellow, we will solve it!


Leave a Reply