php - 无法发送 SMTP 邮件 PHPMailer
问题描述
好吧,我在核心 PHP 上开发了一个通用项目,其中包括邮件系统。一所大学的代表注册了他的大学,并向我的帐户发送了一封邮件,以调查是否提供演示或高级门户所有权。然后整个过程继续。我差不多一年前就部署了它,我工作得很好。但是今天我从存储库中克隆了它
https://github.com/TheAkif/alumni-portal
并在本地主机上运行它,它没有发送电子邮件并给我这些错误:
2019-08-01 06:01:12 CLIENT -> SERVER: AUTH LOGIN
2019-08-01 06:01:12 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-08-01 06:01:12 CLIENT -> SERVER: <credentials hidden>
2019-08-01 06:01:12 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-08-01 06:01:12 CLIENT -> SERVER: <credentials hidden>
2019-08-01 06:01:13 SERVER -> CLIENT: 535-5.7.8 Username and Password not
accepted. Learn more at535 5.7.8 https://support.google.com/mail/?
p=BadCredentials f204sm108618451wme.18 - gsmtp
2019-08-01 06:01:13 SMTP ERROR: Password command failed: 535-5.7.8
Username and Password not accepted. Learn more at535 5.7.8
https://support.google.com/mail/?p=BadCredentials f204sm108618451wme.18 -
gsmtp
SMTP Error: Could not authenticate.
2019-08-01 06:01:13 CLIENT -> SERVER: QUIT
2019-08-01 06:01:13 SERVER -> CLIENT: 221 2.0.0 closing connection
f204sm108618451wme.18 - gsmtp
SMTP Error: Could not authenticate.
mailer.php 看起来像这样。
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'zyx@gmail.com';
$mail->Password = 'xxxxxxxxxx';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('zyx@gmail.com', 'Portal');
$mail->addAddress('xyz@gmail.com', 'Something');
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
}
解决方案
推荐阅读
- python - 检查数字是否有小数的最快方法
- c++ - 为什么通过 boost::iostreams::filtering_istream 窥视 std::cin 会永远阻塞?
- amazon-web-services - 具有两个角色的剧本:运行角色 B 抱怨角色 A 的代码成功运行
- reactjs - 警告:FindNodeDom 在使用 Collapse 时在 Strictmode 中被弃用(来自 react-bootstrap)
- angular - Angular如何映射键和值
- python - Python def 语句参数调用
- html - 如何将 Word 文档转换为 HTML 并将其作为本地文件加载到 WKWebView 中?
- angular - Angular:主题未更新组件
- element - Silverstripe 4 Elemental GroupedDropdownfield inline_editable
- algorithm - 找到一种算法来动态优化队列的大小