【问题标题】:Google SMTP Error: Could not authenticateGoogle SMTP 错误:无法进行身份验证
【发布时间】:2016-05-16 00:53:57
【问题描述】:

以下代码在我将其放在服务器上后不起作用,我在本地环境中也有类似的代码,它运行良好,有什么想法吗?

编辑:我确实将我的 gmail 设置设置为“不太安全”

<?php
$setid = $_POST['setid'];
$promo = $_POST['promo'];


echo "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:";
echo "<br><br>";
echo $promo;

$message=  "Good Sir, your set ID is ".$setid.", and you are eligible for the following deal:"."<br><br>".$promo;

    require "phpmailer/class.phpmailer.php";

    // Instantiate Class  
    $mail = new PHPMailer();

    // Set up SMTP  
    $mail->IsSMTP();               
    $mail->SMTPAuth = true;         
    $mail->SMTPSecure = "ssl"; 
    $mail->Host = "smtp.gmail.com"; 
    $mail->Port = 465; 
    $mail->Encoding = '7bit';

    // Authentication  
    $mail->Username   = "xxx@example.com";
    $mail->Password   = "mypass";

    // Compose
    $mail->SetFrom("jghh@ghh.ca");
    $mail->AddReplyTo("ghh@ghh.ca");
    $mail->Subject = "TryIt";
    $mail->MsgHTML($message);

    // Send To  
    $mail->AddAddress("receiver@hotmail.com", "Recipient Name");
    $result = $mail->Send();
    $message = $result ? 'Successfully Sent!' : 'Sending Failed!';     

    unset($mail);



?>

这是我在网络中得到的 -> 预览:

先生,您的套装 ID 是 100065,您有资格享受以下优惠:

当前促销:下次访问可享受 15% 的折扣!SMTP 错误:无法验证。

【问题讨论】:

标签: php smtp phpmailer


【解决方案1】:

您可能需要启用less secure apps


更改不太安全的应用的帐户访问权限

为了帮助保护 Google Apps 用户的帐户安全,我们可能会减少屏蔽 防止应用程序访问 Google Apps 帐户。作为 Google Apps 用户,您在尝试签名时会看到“密码不正确”错误 如果是这种情况,您有两种选择:

  1. 选项 1:升级到使用最新版本的更安全的应用程序 安防措施。所有 Google 产品(例如 Gmail)都使用最新的 安全措施。
  2. 选项 2:更改您的设置以允许不太安全的应用访问 你的帐户。我们不推荐此选项,因为它可能会使 有人更容易闯入您的帐户。如果你想 仍然允许访问,请按照下列步骤操作:

    2.1。转到“我的帐户”中的“Less secure apps”部分

    2.2。在“访问安全性较低的应用”旁边,选择开启。 (注意 Google Apps 用户:如果您的管理员锁定了不太安全的应用帐户访问权限,则此设置会隐藏。)

如果您仍然无法登录您的帐户,“password incorrect”错误可能是由其他原因引起的。

SRC:https://support.google.com/accounts/answer/6010255?hl=en


更新:

将错误报告添加到您的打开 PHP 标记之后的文件顶部,例如 &lt;?php error_reporting(E_ALL); ini_set('display_errors', 1);

并在 PHPMAILER 上启用调试

$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

看看它是否会产生任何东西。

【讨论】:

  • 实际上我做到了,在它甚至无法在我的本地环境中运行之前,在我降低了它在我的本地环境中运行的安全性之后:)
  • 我很乐意,但它并没有解决我的问题,因为我遇到的问题是当我将代码放在服务器上时出现错误
  • 我已经更新了我的答案,您需要调试才能了解问题所在。
猜你喜欢
  • 2018-04-18
  • 1970-01-01
  • 2021-12-31
  • 2019-01-03
  • 2011-08-04
  • 2012-12-23
  • 1970-01-01
  • 2017-06-22
  • 1970-01-01
相关资源
最近更新 更多