EOF在使用phpmailer时检查是否连接时捕获



我在尝试在本地主机上使用phpmailer时遇到问题。

我已经尝试了至少 2 个小时,使用 phpmailer 连接我的 ionos 1&1 SMTP 服务器。

<<?php 
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;

require 'vendor/autoload.php';
$mail = new PHPMailer(true);         //Passing `true` enables exceptions
try {
    //Server settings
    $mail->SMTPDebug = 4;                                 // Enable verbose debug output
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.ionos.fr';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mymail@mymail.fr';                 // SMTP username
    $mail->Password = 'mypassword';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to
//Recipients
$mail->setFrom('anyrecipient@test.fr', 'Test');
$mail->addAddress('realadress@gmail.com', 'Joe User');     // Add a recipient
//Content
$mail->isHTML(true);                                  // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

 $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo '<br>' . 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
 ?>

实际上,这是错误日志:

<2019-01-02> 客户端: 2019-01-02 09:02:15 SMTP 通知:EOF在检查是否时被捕获 connected 2019-01-02 09:02:15 连接:已关闭 SMTP 错误:无法 连接到 SMTP 主机。SMTP 错误: 无法连接到 SMTP 主机。

无法发送邮件。邮件程序错误: SMTP 错误: 无法连接 到SMTP 主机。

有什么建议/线索吗?

多谢。

阅读文档和示例。您正在使用SMTPSecure = 'tls'Port = 465 .有充分的证据表明,这种组合是行不通的。更改为 ssl 或端口 587,但不能同时更改为两者。

最新更新