I did a very simple thing years ago and now I need it again, but it’s not working.
I just want the users to have their password e-mailed to them if they forgot it when logging in.
I have one page called forgot.php with a form sending email to this page called forgotten.php
<?php
$email = $_POST['email'];
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$result = mysql_query("SELECT user_pass, user_email FROM user_db WHERE user_email='$email'");
$r = mysql_query($result);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "<p>There is no user with this e-mail address in our system.</p><p>Please try again. <a href='forgot.php'>TRY AGAIN</a></p><p>Or set up an account. <a href='sign.php'>NEW ACCOUNT</a></p>";
exit();
} else {
$row=mysql_fetch_array($r);
$password=$row["user_pass"];
$email=$row["user_email"];
$recipient = $email;
$subject = 'Your password';
$message = 'Here is the password you requested from our website: '.$password;
$headers = 'From: info@website.com' . "\\r\
" .'Reply-To: info@website.com' . "\\r\
" .'X-Mailer: PHP/' . phpversion();
print "An email containing the password has been sent to you.";
}
?>