Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 忘记密码显示错误消息_Php_Forgot Password - Fatal编程技术网

Php 忘记密码显示错误消息

Php 忘记密码显示错误消息,php,forgot-password,Php,Forgot Password,我已经建立了一个忘记密码页面,该页面应该向我丢失的密码数据库表插入一个令牌,并向用户发送一封电子邮件,其中包含重置密码的链接,但我没有收到电子邮件,只是在单击提交按钮后,忘记密码页面上出现了一条错误消息,并且有点不确定问题是什么。我的代码在下面 <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $db = new mysqli("localhos

我已经建立了一个忘记密码页面,该页面应该向我丢失的密码数据库表插入一个令牌,并向用户发送一封电子邮件,其中包含重置密码的链接,但我没有收到电子邮件,只是在单击提交按钮后,忘记密码页面上出现了一条错误消息,并且有点不确定问题是什么。我的代码在下面

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$db = new mysqli("localhost", "username", "password", "databasename");
if(isset($_POST['submit'])){
    $email = $_POST['email'];
    $stmt = $db->prepare("SELECT * FROM `users` where `customer_email` = ?");
    $stmt->bind_param('s', $email);
    $stmt->execute();
    $res = $stmt->get_result();
    if($res->num_rows < 1){
        echo "No such email has been found";
    } else{
        $fetch = $res->fetch_assoc();
        $userid = $fetch['user_id'];
        $token = bin2hex(openssl_random_pseudo_bytes(45));
        $from = "noreply@domain.co.uk";
        $url = 'https://www.domain.co.uk/account/passwordreset.php?token='.$token;
        if(mail($email, $url, $from)){
            //if(mail($to,$subject,$message,$url,$headers)){
            $stmt = $db->prepare("INSERT INTO `lost_password`(user_id, token) values(?,?)");
            $stmt->bind_param('is', $userid, $token);
            $stmt->execute();
            $to = $email;
            $subject = "New Password Instructions";
            $message = " Please visit $url to reset your password";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
            // More headers
            $headers .= 'From: <noreply@domain.co.uk>' . "\r\n";
            $mail=mail($to,$subject,$message,$headers);
            if($stmt->affected_rows == 1){
                echo "We have emailed you instructions on how to reset your password";
            } else {
                echo "there was an error";
            }
        }
    }
}
?>

如果您在本地服务器上工作,则会发生错误。您在live server上检查过吗?如果没有,请在live server上进行检查


请缩进您的代码,而不是使用mail()函数。这很难理解。当前您收到的是
echo“有一个错误”或大约500页?我已经缩进了代码,希望它更容易阅读。关于错误,我在
受影响的行之前的页面上收到了
echo“有错误”
条件try
printf(“错误:%s.\n”,$stmt->error)。另外,这将发送两封电子邮件,是否有意?我输入了
printf(“错误:%s.\n”,$stmt->Error)并在页面上显示错误错误:字段“id”没有默认值。有一个错误。也不应该只发送一封电子邮件,我猜这是因为我的代码中有两行邮件
if(mail($email,$url,$from)){'和'$mail=mail($to,$subject,$message,$headers);
if(mail($email,$url,$from))不发送电子邮件可能会有很多问题,这是一个不同的问题。
if(mail($email,$url,$from)){
应该删除。看看
$mail
是什么。我通常使用
swift
phpmailer
,本机功能不是最好的。是的,我在实时服务器上使用它,因为在本地服务器上知道它不起作用,我想我需要看看phpmailer,如前所述