phpmailer - 邮件程序错误:SMTP 错误:无法验证。邮件程序错误:SMTP 错误:无法验证
问题描述
我正在尝试使用 PHPMailer 和 Bluehost 上的 G Suite 帐户电子邮件发送消息,但无法弄清楚为什么它不会发送。
这是我收到的错误:邮件程序错误:SMTP 错误:无法验证。邮件程序错误:SMTP 错误:无法验证。
这是我的PHP代码:
public static function SendMail ($subject, $body, $alt_body, $to, $from, $reply_to = null)
{
if (empty ($reply_to))
$reply_to = $from;
$mail = new PHPMailer (true); // Passing `true` enables exceptions
try
{
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mydomain.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'mymail@mydomain.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom ($from[key ($from)], key ($from));
$mail->addAddress ($to[key ($to)], key ($to)); // Add a recipient
$mail->addReplyTo ($reply_to[key ($reply_to)], key ($reply_to));
//Content
$mail->isHTML (true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AltBody = $alt_body;
$mail->send();
}
catch (Exception $e)
{
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
}
解决方案
推荐阅读
- javascript - 工作日日历 - 通过 JS 动态地将 3 个 DIV 附加在一起 - 尝试将最终 DIV 刷新到右侧
- python - 如何从具有特定条件的DataFrame中的列中选择一组数据?
- c# - 为什么我的抽签动画没有在 Xamarin Forms 中显示?
- javascript - 为什么在对元素应用不透明度时我的文本不可见?
- python - 为什么我可以使用 bot.get_user 函数获得一些用户,而其他用户却不能?[不和谐.py]
- python - Python selenium 问题,等待元素可点击,点击链接与 javascript href
- fetch - Wix fetch 函数使用 HTTPS 从谷歌分析服务中获取资源
- java - 如何忽略肥皂中的 TargetNamespace
- r - 查找数据间隙并拆分更多轨道
- mysql - 无法将 unicode 字符粘贴到 MySQL 控制台