【问题标题】:Use php mailer to send via Gmail - SMTP error [duplicate]使用 php mailer 通过 Gmail 发送 - SMTP 错误 [重复]
【发布时间】:2020-11-23 13:18:45
【问题描述】:

我刚刚通过 gsuite/gmail 注册了一个域,将其用作我的 php 邮件程序的新邮件服务器域。

现在我阅读了大多数相关主题并调整了提示,但我仍然收到错误消息:

Message could not be sent.

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是我的代码:

$mail->Subject = "Tutor found for help";    

//From email address and name
$mail->setFrom('frank@xxx.net', 'xxx.net');

$mail->addAddress("$clientmail", "$clientname");
//$mail->addAddress("nachhilfeanfrage@xxx.net", "xxx.net");

$mail->addReplyTo('frank@xxx.net', 'xxx.net');

$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 2;  // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;  // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled required for GMail
$mail->SMTPAutoTLS = false;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;    // Port for TLS Gmail
$mail->Username = 'xx';   // SMTP username
$mail->Password = 'xx';     

$mail->isHTML(true);
$mail->CharSet = 'UTF-8';

【问题讨论】:

    标签: php smtp phpmailer


    【解决方案1】:

    这可能与Unable to send email using Gmail SMTP server through PHPMailer, getting error: SMTP AUTH is required for message submission on port 587. How to fix? 重复

    您可能不允许在 Gmail 帐户安全仪表板中使用安全性较低的应用。

    【讨论】:

    • 该死的,我知道我在监督一些事情。谢谢!这解决了它!
    【解决方案2】:

    在使用 Gmail 的 SMTP 服务器发送电子邮件之前,您需要在您的 Google 帐户安全设置下进行一些安全和权限级别设置。

    确保禁用两步验证。

    打开“安全性较低的应用”访问权限或点击https://myaccount.google.com/u/0/lesssecureapps

    如果启用了两步验证,则您必须为您的应用程序或设备创建应用程序密码。

    为了安全措施,Google 可能会要求您在登录时完成此额外步骤。点击此处允许使用新设备/应用访问您的 Google 帐户。

    注意:反映任何安全更改可能需要一个小时或更长时间

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 2011-10-16
      • 2011-04-01
      • 2014-10-28
      • 2012-04-19
      • 1970-01-01
      • 2011-08-11
      相关资源
      最近更新 更多