我已经提出忘记密码脚本,用户将被重定向到另一页&他需要输入他的电子邮件ID。如果电子邮件ID存在,则将详细信息发送到该特定的电子邮件ID。如果没有,则发出错误消息。如果电子邮件字段为空,则无法获得错误消息&提交被按下忘记密码的脚本
请帮忙!
<?php
$email="";
$emailErr="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty($_POST["email"]))
{
$emailErr = "Email is required";
}
else
{
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$emailErr = "Invalid email format";
}
}
if($_POST['submit']=='Send')
{
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="testmra"; // Database name
// Connect to server and select databse.
$conn=mysqli_connect($host,$username,$password) or die("cannot connect");
mysqli_select_db($conn,$db_name);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$query="select * from newuser where emailid='$email'";
$result=mysqli_query($conn,$query) or die('Error: Cannot connect to db');
if(mysqli_num_rows($result))
{
$subject="Testing";
$message="Hello Testing";
mail($email, $subject, $message);
}
else
{
$emailErr = "No user exist with this email id";
}
}
}
?>
<html>
<head><title>MRA</title></head>
<body>
<form method="post">
<table align="center">
<tr><td align="right">Email Id :</td><td><input type="text" name="email" value="<?php if (isset($_POST["email"])) { echo $_POST["email"];}?>"></td><td align="left"><input type="submit" name="submit" value="Send"></td></tr>
<tr><td colspan="3" align="center"><font color="red"><?php echo $emailErr; ?></td></tr>
</table>
</form>
</body>
</html>
你应该发布错误 – Med