忘记密码在php中无法正常工作

时间:2016-03-11 16:53:51

标签: javascript php html

我有用php编写的忘记密码的代码。但它没有用。每当我执行它时,它会显示邮件已发送到特定的电子邮件。但是没有邮件发送。 这是代码

<?php
include('./connect1.php');
$username = $_GET['user'];
$password = $_GET['pass'];
$email = "";
$sql = "SELECT email FROM users WHERE username='$username'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result)>0){
    $row = mysqli_fetch_assoc($result);
    $email = $row['email'];
}
else{
    echo "no such user exists";
}
$to = $email;
$from = "gopal@gmail.com";
$message = "
<html>
<head>
<title>Password Reset</title>
</head>
<body>
<p>Please click on this link to reset your passowrd</p>
<a href='www.someone.com/login/reset.php?user=".$username."'>Reset Password</a>
</body>
</html>
";
$subject = "Password Reset";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <gopal@gmail.com>' . "\r\n";
mail($to,$subject,$message,$headers);
echo '<script>alert("Password reset mail has been sent to'.$email.'");</script>';
?>

请帮帮我。

1 个答案:

答案 0 :(得分:1)

这可能是配置错误。如果你坚持使用PHP邮件功能,你将不得不编辑php.ini。

如果您正在寻找更简单,更通用的选项(在我看来),您应该使用PHPMailer