【问题标题】:PHPMailer - SMTP ERROR: Password command failed when send mail from my serverPHPMailer - SMTP 错误:从我的服务器发送邮件时密码命令失败
【发布时间】:2014-03-23 03:41:36
【问题描述】:

我使用 phpmailer() 概念使用 php 脚本从我的共享服务器向用户发送邮件,但即使根据 phpmailer 代码在我的脚本中一切都正确,我也无法发送。

我的代码是这样的:

  $message = " This is testing message from my server";

  $mail = new PHPMailer(); // create a new object
  $mail->IsSMTP(); // enable SMTP
  $mail->Host = "smtp.gmail.com";
  $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
  $mail->SMTPAuth = true; // authentication enabled
  $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
  $mail->Port = 465; // or 587
  $mail->IsHTML(true);
  $mail->Username = "moorthi.mrk10@gmail.com"; // My gmail username
  $mail->Password = "************"; // My Gmail Password
  $mail->SetFrom("moorthi.mrk10@gmail.com");
  $mail->Subject = "Test Mail from my Server";
  $mail->Body = $message;
  $mail->AddAddress($email);
   if($mail->Send())
      {
    print json_encode("SUCCESS");
}
else
{
    echo "Mailer Error: " . $mail->ErrorInfo;

}

注意:我使用“GMail”作为我的 SMTP 服务器,SMTPSecure 是“ssl”,端口是“465”,用户名和密码是我的 GMail 用户名和密码

我使用了 VPS 共享服务器,并将我的 php 脚本保存在该服务器上。

我认为我的php脚本没有问题,但我不知道为什么它不起作用。

我收到了这样的错误。

  2014-02-21 12:30:11   CLIENT -> SERVER: EHLO jkcorporates.com
  2014-02-21 12:30:11   CLIENT -> SERVER: AUTH LOGIN
  2014-02-21 12:30:11   CLIENT -> SERVER: bW9vcnRoaS5tcmsxMEBnbWFpbC5jb20=
  2014-02-21 12:30:11   CLIENT -> SERVER: OTk0MTI0MTE0MA==
  2014-02-21 12:30:11   SMTP ERROR: Password command failed: 534-5.7.14 
  534-5.7.14 i-_eumA> Please log in via your web browser and then try again.
  534 5.7.14 54 k76sm17979938yho.18 - gsmtp
  2014-02-21 12:30:11   CLIENT -> SERVER: QUIT
  " The ERROR is  "  SMTP connect() failed.

请为此提供一些解决方案。
提前致谢。

记住:我使用共享服务器名称“VPS.mydomain.com”,我想使用 GMail 作为我的 SMTP 服务器来向用户发送邮件。

【问题讨论】:

标签: php email smtp phpmailer


【解决方案1】:
  1. 使用网络浏览器登录您的 Gmail 帐户。

  2. 单击此链接以使应用程序能够访问您的帐户:https://accounts.google.com/b/0/DisplayUnlockCaptcha

  3. 点击继续按钮完成该步骤。

  4. 现在再次尝试从您的 PHP 脚本发送电子邮件。它应该可以工作。

【讨论】:

    【解决方案2】:

    您需要使用APP密码。

    访问this链接以查看如何创建一个。

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
    【解决方案3】:

    以防万一,任何人都像我一样在这里结束。 在可能的情况下,尽管启用了对我的谷歌帐户的不安全访问,但它拒绝发送电子邮件并抛出 SMTP 错误:密码命令失败:534-5.7.14。

    (在https://know.mailsbestfriend.com/smtp_error_password_command_failed_5345714-1194946499.shtml找到的解决方案)

    步骤:

    1. 登录您的谷歌帐户

    2. 转到https://accounts.google.com/b/0/DisplayUnlockCaptcha并点击继续启用。

    3. 使用 ssl 将您的 phpmailer 设置为 smtp:

      $mail = new PHPMailer(true);
      
      $mail->CharSet  ="utf-8";
      $mail->SMTPDebug = SMTP::DEBUG_SERVER; // or 0 for no debuggin at all        
      $mail->isSMTP();
      $mail->Host = 'smtp.gmail.com';
      $mail->Port = 465; 
      $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; 
      $mail->SMTPAuth   = true;
      $mail->Username = 'yourgmailaccount';
      $mail->Password = 'yourpassword';
      

    以及其他需要的 $mail 对象属性。

    希望对某人有所帮助!

    【讨论】:

      【解决方案4】:

      除非您完成 g-mail 帐户的两步验证并使用该密码,否则您的邮件将不会在线发送。

      【讨论】:

        【解决方案5】:

        有点晚了,但也许有人会觉得它有用。

        解决问题的链接(您必须登录谷歌帐户):

        https://security.google.com/settings/security/activity?hl=en&pli=1

        https://www.google.com/settings/u/1/security/lesssecureapps

        https://accounts.google.com/b/0/DisplayUnlockCaptcha

        对所发生情况的一些解释:

        此问题可能是由尝试使用电子邮件帐户的“不太安全”的应用程序引起的(这是根据 google 帮助,不确定他们如何判断什么是安全的,什么是不安全的)或者如果您尝试登录多个连续时间或如果您更改国家/地区(例如使用 VPN、将代码移动到不同的服务器或实际尝试从世界不同的地方登录)。

        要解决,我必须:(第一次)

        • 通过网络登录我的帐户
        • 查看最近尝试使用该帐户并接受可疑访问:THIS LINK
        • 禁用阻止可疑应用程序/技术的功能:THIS LINK

        这是第一次工作,但几个小时后,可能是因为我做了很多测试,问题再次出现,并且无法使用上述方法修复。另外我要清除验证码(搞笑图,现在登录任何帐户时要求你重写一个词或一个句子太多次):

        • 登录我的帐户后,我去了HERE
        • 点击继续

        希望这会有所帮助。

        【讨论】:

        • 搜索了一段时间后,我找到了这个页面并为我工作。你能告诉你你是怎么找到这个链接的:accounts.google.com/b/0/DisplayUnlockCaptcha???
        • @YunessMehdian 那是很久以前的事了,所以我不记得我是怎么到那里的。我做了很多研究来解决这个问题,一定是偶然发现了验证码页面。
        • 为我工作,你!
        • 不太安全的应用程序和显示解锁验证码在 000webhost 上为我工作
        • 这对我有用,我一直在努力使用 Outlook,Outlook 不会告诉您登录,只会显示 SMTP 失败消息。非常感谢。
        【解决方案6】:

        使用这个:

        https://www.google.com/settings/u/1/security/lesssecureapps
        https://accounts.google.com/b/0/DisplayUnlockCaptcha
        https://security.google.com/settings/security/activity?hl=en&pli=1
        

        此链接允许访问谷歌帐户

        2017 年 5 月 19 日更新:

        您必须从将要发送电子邮件的 IP 地址访问这些 url

        【讨论】:

        • 我正在使用 Amazon EC2,您能告诉我如何执行此过程吗?
        【解决方案7】:

        如果您是 G Suite 用户,管理员可以解决此问题

        1. 转到您的管理面板
        2. 在顶部搜索栏输入 «Security»(选择 Security with Shield 图标)
        3. 打开基本设置
        4. 转到不太安全的应用部分
        5. 按:转到安全性较低的应用程序的设置 ››

        现在选择一个单选按钮 a) 禁止所有用户访问不太安全的应用程序(推荐) b) 允许用户管理他们对不太安全的应用程序的访问 c) 强制所有用户访问安全性较低的应用程序(不推荐)

        通常它不工作是因为 a)!并且将使用 c) 选项立即开始工作。 b) – 选项将需要为 GSuit 中的每个用户进行更多配置

        希望对你有帮助

        【讨论】:

          【解决方案8】:

          还是无法正常使用的朋友,除了@CallMeBob提供的方法外,还可以尝试以下方法。

          PHP.ini

          1. 进入C:\xampp\php,用记事本编辑php.ini文件。
          2. 按键盘上的CTRL+F,在搜索栏输入sendmail_path,然后点击查找下一个两次.
          3. 现在,您应该在 [mail munction] 部分。

          删除此行的分号: sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
          为此行添加分号: sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

          SendMail.ini

          • 转到C:\xampp\sendmail,用记事本编辑sendmail.ini文件
          • 更改以下内容:
          • smtp_server=smtp.gmail.com
          • smtp_port=465
          • auth_username=your-gmail-username@gmail.com
          • auth_password=your-gmail-password
          • force_sender=your-gmail-username@gmail.com


          注意:
          ** smtp_port 必须与您在 php 代码中编写的内容一致。
          ** 请记住将 your-gmail-usernameyour-gmail-password 更改为您使用的任何帐户。
          **


          希望这可以帮助! :)

          【讨论】:

            【解决方案9】:

            正如其他人已经建议的那样,您可以启用“不太安全”的应用程序,或者您可以简单地从 ssl 切换到 tls

            $mailer->Host = 'tls://smtp.gmail.com';
            $mailer->SMTPAuth = true;
            $mailer->Username = "xxx@gmail.com";
            $mailer->Password = "***";
            $mailer->SMTPSecure = 'tls';
            $mailer->Port = 587;
            

            使用tls 时,无需为安全性较低的应用程序授予访问权限,只需确保启用了 IMAP。

            【讨论】:

              【解决方案10】:

              此错误是由于 gmail 的更多安全功能造成的。

              一旦生成此错误...请登录到您的 gmail 帐户..在那里您可以找到来自 GOOGLE 的安全警报..按照邮件...检查单击以获取不太安全的选项..然后再试一次 phpmailer..

              【讨论】:

                【解决方案11】:

                解决了问题 - PHPMailer - SMTP ERROR: Password command failed when send mail from my server

                    require_once('class.phpmailer.php');
                    include("class.smtp.php"); 
                    $nameField = $_POST['name'];
                    $emailField = $_POST['email'];
                    $messageField = $_POST['message'];
                    $phoneField = $_POST['contactno'];
                    $cityField = $_POST['city'];
                
                $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
                
                $mail->IsSMTP(); // telling the class to use SMTP
                
                $body .= $nameField;
                
                try {
                     //$mail->Host       = "mail.gmail.com"; // SMTP server
                      $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                      $mail->SMTPAuth   = true;                  // enable SMTP authentication
                      $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
                      $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
                      $mail->Port       = 465;   // set the SMTP port for the GMAIL server
                      $mail->SMTPKeepAlive = true;
                      $mail->Mailer = "smtp";
                      $mail->Username   = "xxxxx@gmail.com";  // GMAIL username
                      $mail->Password   = "********";            // GMAIL password
                      $mail->AddAddress('sendto@gmail.com', 'abc');
                      $mail->SetFrom('xxxxxx@gmail.com', 'def');
                      $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
                      $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
                      $mail->MsgHTML($body);
                      $mail->Send();
                      echo "Message Sent OK</p>\n";
                      header("location: ../test.html");
                } catch (phpmailerException $e) {
                      echo $e->errorMessage(); //Pretty error messages from PHPMailer
                } catch (Exception $e) {
                      echo $e->getMessage(); //Boring error messages from anything else!
                }
                

                重要:

                转到谷歌设置并启用“不太安全”的应用程序。它会起作用的。 它对我有用。

                【讨论】:

                  【解决方案12】:

                  我面临同样的问题,并且认为我确实知道为什么会发生这种情况。

                  我使用的 gmail 帐户通常在印度使用,而我使用的网络服务器位于荷兰。

                  Google 通知有人从异常位置进行登录尝试,并要求通过网络浏览器从该位置登录。

                  此外,我不得不接受通过 https://security.google.com/settings/security/activity 对 gmail 帐户的可疑访问

                  但最后我的问题还没有解决,因为我必须从荷兰的某个位置登录到 gmail。

                  我希望这对你有一点帮助! (抱歉,我不阅读此电子邮件地址的电子邮件回复)

                  【讨论】:

                    猜你喜欢
                    • 2018-05-17
                    • 2016-11-13
                    • 1970-01-01
                    • 2017-11-11
                    • 2016-08-14
                    • 1970-01-01
                    • 2018-06-16
                    • 2020-06-09
                    相关资源
                    最近更新 更多