【问题标题】:forgot password is not sending message to my gmail account [duplicate]忘记密码不会向我的 gmail 帐户发送消息[重复]
【发布时间】:2017-12-25 08:00:57
【问题描述】:

电子邮件未发送到 Gmail 帐户 forgot_pass_identity 已设置在桌面上。谁能告诉我我做错了什么? 我检查了代码我没有发现任何错误。

if(isset($_POST['forgotSubmit'])){
//check whether email is empty
    if(!empty($_POST['email'])){
    //check whether user exists in the database
    $prevCon['where'] = array('email'=>$_POST['email']);
    $prevCon['return_type'] = 'count';
    $prevUser = $user->getRows($prevCon);
    if($prevUser > 0){
        //generat unique string
        $uniqidStr = md5(uniqid(mt_rand()));;

        //update data with forgot pass code
        $conditions = array(
            'email' => $_POST['email']
        );
        $data = array(
            'forgot_pass_identity' => $uniqidStr
        );
        $update = $user->update($data, $conditions);

        if($update){
            $resetPassLink = 'http://example.com/resetPassword.php?fp_code='.$uniqidStr;

            //get user details
            $con['where'] = array('email'=>$_POST['email']);
            $con['return_type'] = 'single';
            $userDetails = $user->getRows($con);

            //send reset password email
            $to = $userDetails['email'];
            $subject = "Password Update Request";
            $mailContent = 'Dear '.$userDetails['first_name'].', 
            <br/>Recently a request was submitted to reset a password for your account. If this was a mistake, just ignore this email and nothing will happen.
            <br/>To reset your password, visit the following link: <a href="'.$resetPassLink.'">'.$resetPassLink.'</a>
            <br/><br/>Regards,
            <br/>mysite';
            //set content-type header for sending HTML email
            $headers .= "Content-type:text/html;charset=UTF-8" ;
            //additional headers
            //send email
            mail($to,$subject,$mailContent,$headers);

            $sessData['status']['type'] = 'success';
            $sessData['status']['msg'] = 'Please check your e-mail, we have sent a password reset link to your registered email.';
        }else{
            $sessData['status']['type'] = 'error';
            $sessData['status']['msg'] = 'Some problem occurred, please try again.';
        }
    }else{
        $sessData['status']['type'] = 'error';
        $sessData['status']['msg'] = 'Given email is not associated with any account.'; 
    }

}else{
    $sessData['status']['type'] = 'error';
    $sessData['status']['msg'] = 'Enter email to create a new password for your account.'; 
}
//store reset password status into the session
$_SESSION['sessData'] = $sessData;
//redirect to the forgot pasword page
header("Location:forgotPassword.php");
}

请帮我解决这个问题。在此先感谢:)

【问题讨论】:

  • 您可能正在发送邮件,而 Gmail 可能正在接收它,但随后它会将其作为垃圾邮件丢弃。您的邮件可能没有 SPF 记录或 DKIM。见:support.google.com/mail/answer/…

标签: php email gmail


【解决方案1】:

尝试先添加以下标题。

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: '.$from. "\r\n"; // Valid from address

发送邮件不仅与代码相关联,实际上还取决于其他参数。

如果这不起作用,请参考以下链接。

PHP mail function doesn't complete sending of e-mail

http://form.guide/email-form/php-script-not-sending-email.html

希望这会有所帮助!

【讨论】:

  • 感谢您将此答案标记为正确。乐于助人。
猜你喜欢
  • 2015-10-20
  • 1970-01-01
  • 2023-02-19
  • 1970-01-01
  • 1970-01-01
  • 2020-09-23
  • 2014-06-27
相关资源
最近更新 更多