【发布时间】:2016-04-14 08:04:28
【问题描述】:
大家好! 我正在关注一个教程来了解我们如何在 php.ini 中重置密码。 我作为 localhost 工作。我编写代码,代码没有错误,错误报告也打开,mail() 函数也在工作,但我没有收到任何电子邮件。 此外,在输入无效的用户名时,它也不会给出任何错误。 我阅读并尝试了所有方法,但没有任何方法对我有帮助! 请检查一下我在哪里做错了! 谢谢。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
require_once './include/db_connection.php';
if (isset($_POST['button'])){
$db_email="";
$username = $_POST['username'];
$email =$_POST['email'];
$query="select * from signup where username='$username'";
$result = mysqli_query($link,$query);
$count=mysqli_num_rows($result);
// If the count is equal to one, we will send message other wise display an error message.
if($count>0) {
while ($row = mysqli_fetch_assoc($result)) {
$db_email = $row['email'];
}
if($email == $db_email) {
$code = rand(1000, 10000);
$to =$db_email;
$subject = "Password Reset Link";
$body = "Do not reply of this automated email."
. "Enter the below link to reset passwowrd "
. "http://localhost/Validation/forgotpassword.php?code=$code&username=$username";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mysqli_query($link, "update signup set paareset='$code' where username='$username'");
if(mail($to, $subject, $body,$headers)) {
echo 'Good';
} else {
echo 'mail() not working';
}
echo 'Check your inbox';
} else {
echo 'You have an incorrect email';
}
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="" method="post">
<label> Enter your User ID : </label>
<input type="text" name="username" /><br>
<label> Enter your Eamil address : </label>
<input id="email" type="email" name="email" /><br>
<input id="button" type="submit" name="button" value="Submit" />
</body>
</form>
</html>
【问题讨论】:
-
您的邮件服务器设置正确吗?
-
@DanielMensing 邮件服务器是什么意思?我正在向 gmail 发送电子邮件
-
声明您的代码“没有错误”是一件非常勇敢的事情。你永远可以100%确定这一点。
-
@arkascha 好吧,如果代码没有错误,他们就不需要我们,我们可以继续进行我们可以修复的事情!
-
请记住,
mail()函数实际上并不发送邮件,它所做的只是将邮件请求传递给实际的邮件服务器。根据该邮件服务器的设置方式,您可能必须从该(您的)邮件服务器上存在的有效电子邮件地址发送。