PHPMailer多次发送后出现‘Could not connect to SMTP Host’错误求助
PHPMailer多次发送后出现Could not connect to SMTP Host错误排查
我使用PHPMailer实现用户提交请求后向审批人发送邮件的功能,首次发送邮件可正常送达,但多次发送后出现Could not connect to SMTP Host错误。相关代码如下:
$resAdd = sqlsrv_query($conn, $queAdd) or die(print_r(sqlsrv_errors())); if ($resAdd) { // passing true in constructor enables exceptions in PHPMailer $mail = new PHPMailer(true); $emailBody = "This email is for testing only. Please ignore. Please check the link document. <a href = 'http://localhost/einv/v1/viewDet.php?variable=$refNum'><label>Link</label></a>"; // Server settings $mail->SMTPDebug = 2; // for detailed debug output $mail->isSMTP(); $mail->Host = 'smtp-mail.outlook.com'; $mail->SMTPAuth = true; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 25; $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $mail->Username = 'support_einv@outlook.com'; $mail->Password = 'abc134'; // Sender and recipient settings $mail->setFrom('support_einv@outlook.com', 'e-Inv Notification', 0); $mail->addAddress('user@outlook.com'); // Setting the email content $mail->IsHTML(true); $mail->Subject = "[FOR TESTING, PLEASE IGNORE] Pending Approval : $refNum"; $mail->Body = html_entity_decode($msg_body); $mail->Body = $emailBody; $mail->Debugoutput = 'html'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . print_r(error_get_last(), true); } else { echo 'Message has been sent'; $mail->smtpClose(); } echo "<script type=text/javascript>"; echo "alert('Your request submitted successfully.'),location.href='../viewDet.php?variable=$refNum'"; echo "</script>"; }
我已尝试以下解决方案但均无效:
- 检查防火墙
- 使用
$mail->Host = gethostbyname("smtp-mail.outlook.com"); - 添加
smtpClose() - 启用php.ini中的
extension=php_openssl.dll
请问还有哪些可能导致该错误的原因?
内容的提问来源于stack exchange,提问作者unknownUser24
相关产品推荐
相关产品推荐

