简体   繁体   English

Google Gmail SMTP 设置不允许我使用 PHPMailer 发送电子邮件

[英]Google Gmail SMTP settings not allowing me to send emails with PHPMailer

I created an account on Gmail (becase the previous one was giving me the same problem) so that my application could send emails using google smtp server.我在 Gmail 上创建了一个帐户(因为前一个帐户给了我同样的问题),以便我的应用程序可以使用 google smtp 服务器发送电子邮件。

I'm using the PHPMailer library and asked it to show any log errors.我正在使用 PHPMailer 库并要求它显示任何日志错误。

I always get a message similar to this.我总是收到与此类似的消息。 It vary a little, sometimes it is shorter and sometimes longer, depending on my configuration它略有不同,有时更短,有时更长,具体取决于我的配置

2015-08-01 05:07:01 CLIENT -> SERVER: EHLO www.lavile.com 
2015-08-01 05:07:01 CLIENT -> SERVER: AUTH LOGIN 
2015-08-01 05:07:01 CLIENT -> SERVER: Y29udGF0by5sYXZpbGVAZ21haWwuY29t 
2015-08-01 05:07:01 CLIENT -> SERVER: WXlhdUgxMnM= 2015-08-01 05:07:01  SMTP ERROR: Password command failed: 534-5.7.9 Please log in with your web browser and then try again. Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp 
2015-08-01 05:07:01 SMTP Error: Could not authenticate. 
2015-08-01 05:07:01 CLIENT -> SERVER: QUIT 
2015-08-01 05:07:01 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting string(82) "SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"

This is my script这是我的脚本

    $mail->Username = "myusername@gmail.com";
    $mail->Password = "mypassword";

    $mail->IsSMTP(); // enable SMTP
    $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->Host = "smtp.gmail.com";
    $mail->Port = 465; // or 587
    $mail->IsHTML(true);
    $mail->SetFrom($mail->Username, 'Contato Lavile');
    $mail->addAddress($mail->Username, "Contato Lavile");
    $mail->Subject = 'Novo contato no site Lavile';
    $mail->Body = $text;
    $mail->IsHTML(true);
    $mail->AltBody = $text;

Also GMAIL is sending automatic emails to myself alerting me that a new login attempt was blocked.此外,GMAIL 正在向自己发送自动电子邮件,提醒我新的登录尝试被阻止。 I even changed some settings on my gmail to make it work but everything failed我什至更改了我的 gmail 上的一些设置以使其正常工作,但一切都失败了

Any idead?有什么想法吗? Do you know what could be happening?你知道会发生什么吗?

I would recommend to actually read the error message:我建议实际阅读错误消息:

... 534-5.7.9 Please log in with your web browser and then try again. ... 534-5.7.9 请使用您的网络浏览器登录,然后重试。 Learn more at 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp在 534 5.7.9 https://support.google.com/mail/answer/78754 b16sm3352387qga.48 - gsmtp 了解更多信息

When reading this site you will find something about supporting client which provide only less secure methods of authorization.阅读本网站时,您会发现有关支持客户端的内容,这些内容仅提供不太安全的授权方法。 Your client is one of these so follow the link to learn how to enable support for these application in gmail.您的客户就是其中之一,因此请点击链接了解如何在 gmail 中启用对这些应用程序的支持。

您可以在没有自己的 smtp 服务器的情况下发送电子邮件:1) 从 dns 获取收件人 mx 主机名 2) 将电子邮件发送到端口 25

Not saying this is necessarily what happened to the topic opener but I had exactly this same error today.并不是说这一定是主题开启者发生的事情,但我今天遇到了完全相同的错误。 And the reason I got it was because I created a new e-mail address and you first need to log in to Gmail via the browser once before you can use smtp.我得到它的原因是因为我创建了一个新的电子邮件地址,您首先需要通过浏览器登录 Gmail 一次,然后才能使用 smtp。

After logging in to the Gmail web client via the browser and going over the initial flow I was able to send via the smtp endpoint.通过浏览器登录 Gmail 网络客户端并完成初始流程后,我能够通过 smtp 端点发送。

$mail->Host = "smtp.gmail.com"; should be something like:应该是这样的:

$mail->Host = "mail.yourdomain.com";//replace your domain name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM