【发布时间】:2021-03-23 02:24:14
【问题描述】:
我将代码组织成这样:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/Exception.php';
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/PHPMailer.php';
require '/home/g/grablmz2/psywomenandmen.ru/public_html/ads/libs/PHPMailer/SMTP.php';
$mail = new PHPMailer(true);
try {
echo 'start';
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'hidden'; // SMTP username
$mail->Password = 'hidden'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('hidden', 'Mailer');
$mail->addAddress('hidden', 'Michael');
// Content
$mail->Subject = 'Test';
$mail->Body = 'Test';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Gmail 中的“安全性较低的应用程序”已开启。通过复制并粘贴到浏览器来对登录名和密码进行双重检查。
例外:
start2020-12-11 16:36:00 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP c16sm931756lfb.236 - gsmtp
2020-12-11 16:36:00 CLIENT -> SERVER: EHLO psywomenandmen.ru
2020-12-11 16:36:00 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [5.101.156.177]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2020-12-11 16:36:00 CLIENT -> SERVER: STARTTLS
2020-12-11 16:36:00 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2020-12-11 16:36:00 CLIENT -> SERVER: EHLO psywomenandmen.ru
2020-12-11 16:36:00 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [5.101.156.177]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2020-12-11 16:36:00 CLIENT -> SERVER: AUTH LOGIN
2020-12-11 16:36:00 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-12-11 16:36:00 CLIENT -> SERVER: [credentials hidden]
2020-12-11 16:36:00 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-12-11 16:36:00 CLIENT -> SERVER: [credentials hidden]
2020-12-11 16:36:01 SERVER -> CLIENT: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 bXAEJKkJeqWCiVzTTlBWq9rxftBEamfSnaWIVJ0_dKDfgIuJ6a7XbSNz62WFwSuLLEQAO534-5.7.14 vcrBWQgPPNpki5WeHQlOd9wE2RNXirLYC1_og20m_xsWH4wka8pkDZJz0Iv-LySW>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 c16sm931756lfb.236 - gsmtp
2020-12-11 16:36:01 SMTP ERROR: Password command failed: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbv534-5.7.14 bXAEJKkJeqWCiVzTTlBWq9rxftBEamfSnaWIVJ0_dKDfgIuJ6a7XbSNz62WFwSuLLEQAO534-5.7.14 vcrBWQgPPNpki5WeHQlOd9wE2RNXirLYC1_og20m_xsWH4wka8pkDZJz0Iv-LySW>534-5.7.14 Please log in via your web browser and then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 c16sm931756lfb.236 - gsmtp
SMTP Error: Could not authenticate.
2020-12-11 16:36:01 CLIENT -> SERVER: QUIT
2020-12-11 16:36:01 SERVER -> CLIENT: 221 2.0.0 closing connection c16sm931756lfb.236 - gsmtp
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
我在端口和其他选项方面做错了吗?
【问题讨论】:
标签: php gmail phpmailer gmail-api