【问题标题】:Why Username and Password not accepted when I send mail in php?为什么我在 php 中发送邮件时不接受用户名和密码?
【发布时间】:2015-09-29 14:24:50
【问题描述】:

您好,这是我的问题:

我想发送一封邮件,这是我的邮件代码:

<?php

require "vendor/autoload.php";

class HelperMail{

  private $oPhpMailer;


    function __construct(){

        $this->oPhpMailer = new PHPMailer();
        $this->oPhpMailer->isSMTP();
        $this->oPhpMailer->SMTPDebug = 2;
        $this->oPhpMailer->Debugoutput = 'html';
        $this->oPhpMailer->SMTPSecure = 'tls';
        $this->oPhpMailer->SMTPAuth = true;

    }
            public function mailFrom($from,$usuario){
              $this->oPhpMailer->setFrom($from,$usuario);             
            }
            public function mailPort($puerto){
              $this->oPhpMailer->Port = $puerto;   
            }
            public function mailUsuario($usuario){
              $this->oPhpMailer->Username = $usuario;   
            }
            public function mailPassword($pass){
              $this->oPhpMailer->Password = $pass;       
            }
            public function mailHost($host){
              $this->oPhpMailer->Host = $host;      
            }
            public function mailSubject($subject){
              $this->oPhpMailer->Subject = $subject;       
            }
            public function mailAddress($address){
              $this->oPhpMailer->addAddress($address);     
            }
            public function mailAltBody(){
              $this->oPhpMailer->AltBody = 'This is a plain-text message body';     
            }

            public function mailHtml(){

            }

            public function setData ($usuarios){ 

              $htmlMail = $this->oPhpMailer->msgHTML(file_get_contents('helpers/mailAvisoSinTareasReg/contenido.html'));
              $htmlMailChange = str_replace("TRABAJO","LAZOS",$htmlMail);
              $this->sendMail();
            }


            public function sendMail(){

            if (!$this->oPhpMailer->send()) {
                        echo "Mailer Error: " . $this->oPhpMailer->ErrorInfo;
                    } else {
                        echo "Message sent!";
                    }

            }
    }
?>

我有这个错误:

我知道用户和通行证都ok,所以不知道是什么问题。

我该如何解决这个问题? ,对不起我的英语

【问题讨论】:

  • Learn more at 535 5.7.8 https://support.google.com/mail/answer/14257?你看过这个……对吧?
  • ...以及 github 上的故障排除指南进一步向下链接。

标签: php sendmail phpmailer


【解决方案1】:

如果您收到以下错误:

SMTP -> ERROR:Password not accepted from server. Code: 535 Reply: 535-5.7.1 Please log in with your web browser and then try again.

即使 Gmail 帐户凭据正确,Google 的服务器仍可能阻止服务器尝试进行身份验证(很可能是由于新的服务器位置和/或最近的密码更改)。

要解决此问题,请确保您在浏览器中使用相同的 Gmail 帐户登录,然后只需打开下面的链接并逐步完成验证过程: https://accounts.google.com/b/0/DisplayUnlockCaptcha

这将允许您在大约 10 分钟内访问您的 Gmail 帐户,以便检测到新的身份验证服务器。请务必在此时间段内再次尝试进行身份验证。”

SRC:http://www.rocketideas.com/2012/05/gmail-error-password-not-accepted-from-server-solved/


提示: 您还应该查看错误后显示的 url (https:/support.google...)。

【讨论】:

  • 我很抱歉,但我认为复制和粘贴外包的东西不应该被视为一个好的答案。我没有投反对票或其他任何事情,但这主要证明 OP 没有做出足够的研究努力,因此它的问题是无效的。
  • 我同意,OP 没有进行足够的研究,因为我在 1 分钟内找到了答案。只要您提及来源,复制并粘贴来自不同网站的答案就不会被视为不好的做法。
【解决方案2】:

在 google 中允许安全性较低的应用。 https://myaccount.google.com/lesssecureapps

【讨论】:

    【解决方案3】:

    错误 1:密码命令失败:534-5.7.9 需要应用程序特定密码 回答: 这主要发生在 SMTP 邮件服务器凭据正确但未提供应用程序特定密码时。

    错误 2:SMTP 错误:密码命令失败:535-5.7.8 用户名和密码不被接受 回答: 如果您遇到此错误,则这主要是因为应用程序专用密码不正确。

    转到下面的链接 https://support.google.com/accounts/answer/185833?hl=en

    通过选择应用程序(其他)创建应用程序密码并复制生成的密码并将此密码粘贴到 gmail 密码的位置。

    【讨论】:

      【解决方案4】:

      允许 less secure app access 使用您的 gmail 帐户

      【讨论】:

        猜你喜欢
        • 2018-02-07
        • 2018-03-03
        • 1970-01-01
        • 2020-11-08
        • 1970-01-01
        • 1970-01-01
        • 2015-11-13
        • 2021-07-25
        • 1970-01-01
        相关资源
        最近更新 更多