php - PHPMailer 挂起邮件发送
问题描述
我尝试向用户发送电子邮件,但一旦$mail->send()
被执行,什么也没有发生,网页卡住并挂了 5 分钟。
这是$mail
设置:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once __DIR__ . '/../PHPMailer/src/Exception.php';
require_once __DIR__ . '/../PHPMailer/src/PHPMailer.php';
require_once __DIR__ . '/../PHPMailer/src/SMTP.php';
class Email {
private $mail;
function __construct() {
$config = parse_ini_file(__DIR__ . '/../../private/config.ini');
$this->mail = new PHPMailer(true);
$this->mail->IsSMTP();
$this->mail->SMTPDebug = 4;
$this->mail->SMTPAuth = true;
$this->mail->CharSet = 'utf-8';
$this->mail->Secure = 'ssl';
$this->mail->Host = $config['smtphost'];
$this->mail->Port = 465;
$this->mail->Username = $config['smtpusername'];
$this->mail->Password = $config['smtppassword'];
}
}
5 分钟后,此消息显示在浏览器中:
2020-04-01 22:53:58 Connection: opening to ##mysmtphost##:465, timeout=300, options=array()
2020-04-01 22:53:58 Connection: opened
我已经检查了任何类似的问题及其解决方案,但这些似乎都对我的问题没有帮助。
发送:
$mail = new Email();
$mail->AddAddress($_POST['forgot_password']['email'], $foundEmail['username']);
$fromEmailAddress = ###MyHostEmailAddress###;
$fromName = ###name...###;
$mail->SetFrom($fromEmailAddress, $fromName);
$subject = ###subject..###;
$msgBody = $url;
$mail->Subject($subject);
$mail->Body($msgBody);
if($mail->Send())
$validationMessage = 'TEST'
解决方案
尝试在发送函数之后返回一些东西,因为我认为(所以我不确定 100%,但我有这样的问题)调用发送函数时的 phpmailer 使用线程,所以它使用线程发送邮件,所以如果你的代码结束或死亡如果没有返回,线程也将停止或死亡。你也可以转储 send() 的结果,如果它是真的,这意味着你的配置是好的,否则意味着你有问题
推荐阅读
- cross-domain - 使用 nuxtjs/axios 跨域
- postgresql - JSONB 列:仅对存储在具有混合 JSONB 内容的列中的数组的内容进行排序
- java - 正则表达式为运行时 exec java 做一个文件路径
- c# - 使用文本文档打开时显示敏感信息的 exe
- conv-neural-network - CNN 权重卡住了
- android - 使用android的mediaRecorder的文件大小限制?
- python-3.x - Selenium/Python:无法使用任何 find_element_by_* 方法找到元素
- php - Issues Running Bash Script with PHP Parameters
- proxy - DISTCP 到 PROXY 后面的 GCS
- css - Flexbox 项目的高度在 IE 上折叠