【发布时间】:2015-04-17 19:40:05
【问题描述】:
我在下面的 PHP 中有一个忘记密码的脚本。该脚本的想法是提交电子邮件地址,然后脚本查看该电子邮件地址是否在数据库中,然后更改密码,然后将带有临时地址的电子邮件发送到表单中提交的电子邮件。
该脚本似乎更改了密码并执行了所有操作,但它似乎并未实际发送带有临时密码的电子邮件。
我已经很久没有使用这个脚本(或 PHP),所以任何帮助都将不胜感激。
<?php # forgot_password.php
require_once ('./includes/config.inc.php');
$page_title = 'Forgot Password';
include ('./includes/header.html');
if (isset($_POST['submitted'])) { // Handle the form.
require_once ('database-connection.php');
if (empty($_POST['user_email'])) { //Validate the email address.
$uid = FALSE;
echo 'You forgot to enter your email address!';
} else {
$query = "SELECT ID FROM wp_users WHERE user_email='". escape_data($_POST['user_email']) . "'";
$result = mysql_query ($query)or trigger_error("Query:$query\n<br />MySQL Error: " .mysql_error());
if (mysql_num_rows($result)== 1) {
list($uid) = mysql_fetch_array ($result, MYSQL_NUM);
} else {
echo 'This email address is not registered';
$uid = FALSE;
}
}
if ($uid) { // If everything's OK.
$p = substr ( md5(uniqid(rand(),1)), 3, 10);
$query = "UPDATE wp_users SET user_pass=SHA('$p') WHERE ID=$uid";
$result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " .mysql_error());
if (mysql_affected_rows() == 1) {
$body = "Your password to log into the site has been temporarily changed to '$p'.
Please log in using this password and your username. At that time you may change your password to something more familiar.";
mail($_POST['user_email'], 'Your temporary password.', $body,
'From:info@website.com.au'); //From email address
echo 'Your password has been temporarily changed.
An email from info@website.com.au will be sent to your registered email address with a new, temporary password which you can log in with.
Once you have logged in with this password, you may change it by clicking on the "Change Password" link at the bottom of your screen.';
mysql_close(); // Close the database connection.
include ('./includes/footer.html'); // Include the HTML footer.
exit();
} else { //If it did not run OK.
echo 'Your password could not be changed due to a system error. We apologize for any inconvenience.';
}
} else { // Failed the validation test.
echo '<p><font color="red"size="+1">Please try again.</font></p>';
}
mysql_close(); // Close the database connection.
} // End of the main Submit conditional.
?>
<p>Enter your email address below and your password will be reset.</p>
<form action="forgot_password.php" method="post">
<p><b>Email Address:</b> <input type="text"
name="user_email" size="30" maxlength="40" value="<?php if (isset($_POST['user_email'])) echo $_POST['user_email']; ?>" /></p>
<div align="center"><input type="submit" name="submit" value="Reset My Password" /></div>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>
【问题讨论】:
标签: php mysql forgot-password