How to develop php script for forget password

Here we are developing code of how to develop php script for forget password. this is very simple and easy script for forget password in php.
you just have need some knowledge of php, mysql and some basic php applications such as login script and user registration and some mysql queries.

Lets we Start Php Code for Forget Password Script.
First we have need to create connection file connect to database.

/** The name of the database */
define('DB_NAME', 'phpkidadb');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', '');

/** MySQL hostname */
define('DB_HOST', 'localhost');

mysqli_select_db($con, DB_NAME);

After created connection file we have need create php cript for forget password.
so here we will check form is submit or not if form is submit, then we will check enter email id by user is exist in user table of database, if email id exist so execute code of send password on email and show message to user. and if email id not exist in this case show error message to user.

PHP Code For Forget Password

 $pres=mysqli_query($con, "select email, password from users where email='$email'");
 $to = $email;

// subject
$subject = ' Reset Your Password ';

// message
$message = '
<title> Forget Password Script In PHP - PHPKIDA </title>


// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: Forget Password <>' . "\r\n";

// Mail it
mail($to, $subject, $message, $headers);

echo "Your Password Sent On Your Email Id, Check and login !";
 else{echo "Email Id Does Not Match ! Please Try Again And Check Your Email Id.";}

HTML Code For Form

 <form method="post">
 <input name="email" type="text" placeholder="Enter Your Email Id" required>
 <input type="submit" value="Reset Password" name="fpass">

I Hope You Like This Tutorial. If You Have Any Question Please Leave comment we will be focus on. Thank For Visit.

About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.