我正在为我的用户创建一个忘记密码页面,但它无效。我正在学习一个教程,当做教程的人做了适合他们的事情时,它对我不起作用。例如,查询不会搜索用户名和电子邮件是否存在。当我点击提交时,该页面只是刷新而且就是这样,我没有收到任何电子邮件。有人可以帮助我并告诉我我做错了什么吗?
forgotpass.php:
include("connect.php");
GLOBAL $email;
GLOBAL $submit;
if (empty($_POST["username"])) {
echo"fill in username to sign up";
}
if (empty($_POST["email"])) {
echo"fill in email to sign up";
}
if(isset($_POST['submit'])) {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$query = mysqli_query($conn ,"SELECT * FROM users WHERE username='" . $username . "'");
$numrow = mysqli_num_rows($query);
if($numrow != 0 ){
while($row = mysqli_fetch_assoc($query))
{
$db_email = $row ['email'];
}
if($email == $db_email){
$code = rand(10000, 1000000);
$to = $db_email;
$subject = "Password reset";
$body = "
This is an automated email. Please DO NOT reply to this email.
Click the link below or paste it in your browser.
http://localhost/testsocialnetwork/forgotpass.php?email=brandont264%40gmail.com&submit=Submit?code=$code&username=$username
";
mysqli_query("UPDATE users SET passreset='$code' WHERE username='" . $username . "'");
mail($to, $subject, $body);
echo"Check your email";
} else{
echo"email is incorrect";
}
} else {
echo"That username doesn't exists.";
}
}
形式:
<form>
<center><p id="p1">Your E-mail: <input size="30" type="text" name="email" /> </p>
<center><p id="p1">Your username: <input size="30" type="text" name="username" /></p>
<input type="submit" name="submit" value="Submit" />
</center>
</form>
更新!!!
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
我收到了这个错误,并且对每个试图帮助我的人都非常诚实......我不知道这意味着什么。我可以帮忙吗?