【问题标题】:Send mail SMTP GMail and PHPMailer发送邮件 SMTP GMail 和 PHPMailer
【发布时间】:2017-11-04 20:21:57
【问题描述】:

我在使用 Google SMTP 和最新版本的 PHPMailer 发送邮件时遇到问题。这里有很多问题,但答案对我不起作用。 我正在使用带有免费子域000webhost 的免费托管。 这是我从 PHPMailer docs 发送电子邮件的标准 PHP 代码:

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'GMAIL EMAIL ACCOUNT';
$mail->Password = 'MY PASSWORD FOR GMAIL EMAIL ACCOUNT';
$mail->SMTPSecure = 'tlc';
$mail->Port = 587;
$mail->SMTPDebug  = 3;
$mail->setFrom('EMAIL ADDRESS', 'EXAMPLE');
$mail->addAddress('ADDRESS TO SEND', 'From contact form');

$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

我得到这个错误:

.... 2017-06-03 15:15:33 服务器 -> 客户端:535-5.7.8 用户名和密码不被接受。了解更多信息 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 SMTP 错误:密码命令失败:535-5.7.8 用户名和密码不被接受。了解更多信息 535 5.7.8 https://support.google.com/mail/?p=BadCredentials 203sm11822739ywk.62 - gsmtp 2017-06-03 15:15:33 SMTP 错误:无法验证。 .....

如果我将ssl 与端口465 一起使用,我会看到同样的错误。

在我的Gmail 电子邮件帐户中,2 工厂身份验证是 OFFAllow less secure appsON

我真的不知道该怎么办。

【问题讨论】:

  • 没有tlc for SMTPSecure 这样的设置。

标签: php email smtp phpmailer


【解决方案1】:

我找到了一种创建Google App Password 的方法并使用它来代替Gmail 帐户密码:

$mail->Password = 'GOOGLE APP PASSWORD';

创建应用密码需要设置Two factory authentication:https://support.google.com/accounts/answer/185839?hl=en,然后可以创建应用密码-https://support.google.com/accounts/answer/185833?hl=en

【讨论】:

  • 我创建了应用密码,但仍然失败
  • @Scott,奇怪,什么反应?
  • 当我得知如果我只授权/确认我们使用的“发件人”地址就可以使用 Amazon SES 时,我放弃了它。然后我只需要配置sendmail(postfix)通过SES中继,本地php可以使用本地sendmail或php内置邮件发送电子邮件。
【解决方案2】:
  1. 通过https://myaccount.google.com 登录您的 Google 帐户
  2. 点击左侧菜单中的“安全”。
  3. 向下滚动到“不太安全的应用访问”部分。

    点击“开启访问(不推荐)”。

https://support.google.com/mail/thread/23875320?hl=en

【讨论】:

    猜你喜欢
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2018-09-10
    相关资源
    最近更新 更多