Google SMTP错误:无法验证 [英] Google SMTP Error: Could not authenticate

查看:704
本文介绍了Google SMTP错误:无法验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码一旦将其放到服务器上就无法使用,我在本地环境中也能使用类似的代码,并且可以完美运行,有什么想法吗?

The following code does not work once i put it on the server, I have similar code working on my local environment and it works perfectly, any ideas?

我确实将gmail设置设置为安全性较低"

edit: i did set my gmail setting to "less secure"

<?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);



?>

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

This is what I get in Network -> Preview:

好先生,您的ID为100065,您有资格进行以下交易:

Good Sir, your set ID is 100065, and you are eligible for the following deal:

当前促销:下一次访问可享受15%的折扣!SMTP错误:无法通过身份验证.

Current Promotion: Enjoy 15% discount on your next visit!SMTP Error: Could not authenticate.

推荐答案

您可能需要启用少安全的应用程序

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

Change account access for less secure apps

为帮助确保Google Apps用户的帐户安全,我们可能会减少屏蔽次数 保护应用程序访问Google Apps帐户.作为Google Apps 用户,尝试签名时会看到密码错误"错误 在这种情况下,您有两个选择:

To help keep Google Apps users' accounts secure, we may block less secure apps from accessing Google Apps accounts. As a Google Apps user, you will see a "Password incorrect" error when trying to sign in. If this is the case, you have two options:

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

  1. Option 1: Upgrade to a more secure app that uses the most up to date security measures. All Google products, like Gmail, use the latest security measures.
  2. Option 2: Change your settings to allow less secure apps to access your account. We don't recommend this option because it might make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

2.1.转到我的帐户"中的"缺少安全应用"部分

2.1. Go to the "Less secure apps" section in My Account

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

2.2. Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)

如果仍然无法登录帐户,请使用"密码 错误"错误可能是由其他原因引起的.

If you still can't sign in to your account, the "password incorrect" error might be caused by a different reason.

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

更新:

在打开PHP标记(例如<?php error_reporting(E_ALL); ini_set('display_errors', 1);

Add error reporting to the top of your file(s) right after your opening PHP tag for example <?php error_reporting(E_ALL); ini_set('display_errors', 1);

并在PHPMAILER上启用调试

and enable debug on PHPMAILER

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

查看它是否产生任何东西.

to see if it yields anything.

这篇关于Google SMTP错误:无法验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆