忘记密码没有向我的Gmail帐户发送邮件[重复]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了忘记密码没有向我的Gmail帐户发送邮件[重复]相关的知识,希望对你有一定的参考价值。

这个问题在这里已有答案:

电子邮件未发送到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");
}

请帮我解决这个问题。提前致谢 :)

答案

首先尝试添加以下标题。

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

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

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

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

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

希望这可以帮助 !

以上是关于忘记密码没有向我的Gmail帐户发送邮件[重复]的主要内容,如果未能解决你的问题,请参考以下文章

通过 PHP 从免费的 Gmail 帐户发送 [重复]

.Net通过Gmail发送邮件[重复]

使用设计和 Gmail smtp 服务器发送邮件

如何向我的 gmail 发送电子邮件而不是托管

如何在没有身份验证的情况下直接向 SMTP 服务器发送邮件?

我的邮件没有被php函数mail()发送[重复]