PHPMailer错误使用GMAIL:邮件程序错误:SMTP连接() [英] PHPMailer ERROR USING GMAIL: Mailer Error: SMTP connect()

查看:289
本文介绍了PHPMailer错误使用GMAIL:邮件程序错误:SMTP连接()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用我的gmail帐户从本地主机发送电子邮件。
我也尝试在网络甚至是本网站上找到答案,但没有任何帮助。



这是代码:

  require 'PHPMailer的主/ PHPMailerAutoload.php'; 

$ mail = new PHPMailer(); //创建一个新对象
$ mail-> IsSMTP(); //启用SMTP
$ mail-> SMTPDebug = 2; //调试:1 =错误和消息,2 =仅消息
$ mail-> SMTPAuth = true; //启用认证
$ mail-> SMTPSecure ='ssl'; //启用安全转接功能需要Gmail
$ mail-> Host =smtp.gmail.com;
$ mail->端口= 465; //或587
$ mail-> IsHTML(true);
$ mail->使用者名称=myUser@gmail.com;
$ mail->密码=myUserPass;
$ mail-> SetFrom(myUser@gmail.com);
$ mail-> Subject =Test;
$ mail-> Body =hello;
$ mail-> AddAddress(OtherUser@gmail.com);

if(!$ mail-> Send()){
echo邮件错误:。 $ MAIL-> ERRORINFO;
} else {
echoMessage has been sent;
}

我得到的完整错误:


2017-04-03 10:33:15服务器 - >客户端:220 smtp.gmail.com ESMTP
p7sm17594308wrc.19 - gsmtp 2017-04-03 10 :33:15客户端 - >服务器:EHLO
localhost 2017-04-03 10:33:15服务器 - >客户端:250-smtp.gmail.com在
您的服务,[46.117.89.127] 250-SIZE 35882577 250-8BITMIME 250-AUTH
LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2017-04-03 10:33: 15客户端 - >服务器:AUTH LOGIN 2017-04-03
10:33:15服务器 - >客户端:334 VXNlcm5hbWU6 2017-04-03 10:33:15客户端
- >服务器:bXlVc2VyQGdtYWlsLmNvbQ = = 2017-04-03 10:33:15服务器 - >客户端:334 UGFzc3dvcmQ6 2017-04-03 10:33:15客户端 - >服务器:
bXlVc2VyUGFzcw == 2017-04-03 10:33:15服务器 - >客户端:535-5.7.8
不接受用户名和密码。了解更多信息,请访问535 5.7.8
https://support.google.com/ mail /?p = BadCredentials p7sm17594308wrc.19 -
gsmtp 2017-04-03 10:33:15 SMTP错误:密码命令失败:
535-5.7.8未接受用户名和密码。了解更多信息,请访问535 5.7.8
https://support.google.com/邮件/?p = BadCredentials p7sm17594308wrc.19 -
gsmtp 2017-04-03 10:33:15 SMTP错误:无法验证。
2017-04-03 10:33:15客户端 - >服务器:QUIT 2017-04-03 10:33:16服务器
- >客户端:221 2.0.0关闭连接p7sm17594308wrc.19 - gsmtp 2017-04-03 10:33:16 SMTP连接()失败。
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting邮件程序
错误:SMTP connect()失败。
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting


我试图删除:

  $ mail-> SMTPSecure ='ssl'; //启用安全传输需要Gmail 

或者将端口更改为25/587,但没有帮助。
是否有人知道如何解决这个问题?

解决方案

假设您输入的用户名和密码正确,授权外部应用程序使用gmail。



请按照下面的步骤进行授权:


  1. 首先,转至 Google帐户管理页面

  2. 关联的应用程序&点击允许安全性较低的应用:ON

如果您的Gmail帐户启用了两步验证,那么它不起作用,使用自动生成的密码



更新:

虽然转向允许安全性较低的应用程序:ON 可能会解决您的问题,但应将其作为故障排除提示,而不是最终解决方案。


I tried to send email from my localhost using my gmail account. I also tried to find answers in the web and even in this website but nothing helped me. I am using XAMPP.

This is the code:

require 'PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer();         // create a new object
$mail->IsSMTP();                 // enable SMTP
$mail->SMTPDebug = 2;            // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;          // authentication enabled
$mail->SMTPSecure = 'ssl';       // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;               // or 587
$mail->IsHTML(true);
$mail->Username = "myUser@gmail.com";
$mail->Password = "myUserPass";
$mail->SetFrom("myUser@gmail.com");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("OtherUser@gmail.com");

if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message has been sent";
}

The full error which I got:

2017-04-03 10:33:15 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP p7sm17594308wrc.19 - gsmtp 2017-04-03 10:33:15 CLIENT -> SERVER: EHLO localhost 2017-04-03 10:33:15 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [46.117.89.127] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2017-04-03 10:33:15 CLIENT -> SERVER: AUTH LOGIN 2017-04-03 10:33:15 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2017-04-03 10:33:15 CLIENT -> SERVER: bXlVc2VyQGdtYWlsLmNvbQ== 2017-04-03 10:33:15 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2017-04-03 10:33:15 CLIENT -> SERVER: bXlVc2VyUGFzcw== 2017-04-03 10:33:15 SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials p7sm17594308wrc.19 - gsmtp 2017-04-03 10:33:15 SMTP ERROR: Password command failed: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials p7sm17594308wrc.19 - gsmtp 2017-04-03 10:33:15 SMTP Error: Could not authenticate. 2017-04-03 10:33:15 CLIENT -> SERVER: QUIT 2017-04-03 10:33:16 SERVER -> CLIENT: 221 2.0.0 closing connection p7sm17594308wrc.19 - gsmtp 2017-04-03 10:33:16 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I tried to delete that:

$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail

Or changing the port to 25/587 but it did not help. Does someone know how to fix that?

解决方案

Assuming that your username and password entered is correct, you need to authorize the external application use of gmail.

Follow the next steps and authorize to make it:

  1. First, go to your Google Account Management page
  2. Under the Connected apps & sites, click Allow less secure apps: ON

In case it does not work, if your gmail account has 2-step verification enabled, use an auto-generated password.

Update:

Although turning Allow less secure apps: ON might solve your problem, it should be taken as a troubleshooting tip and not as the final solution.

这篇关于PHPMailer错误使用GMAIL:邮件程序错误:SMTP连接()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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