使用phpmailer时检查是否已连接EOF

时间:2019-01-02 09:22:40

标签: smtp phpmailer

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

我一直在尝试使用ionos连接phpmailer 1&1 SMTP服务器至少2个小时。

<<?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;


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 09:02:04连接:打开smtp.ionos.fr:465,   超时= 300,options = array()2019-01-02 09:02:04连接:已打开   2019-01-02 09:02:15 SMTP INBOUND:“” 2019-01-02 09:02:15服务器->   客户端:2019-01-02 09:02:15 SMTP通知:EOF在检查是否为EOF时被捕获   已连接2019-01-02 09:02:15连接:关闭SMTP错误:无法   连接到SMTP主机。 SMTP错误:无法连接到SMTP主机。

     

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

有什么建议/线索吗?

非常感谢。

1 个答案:

答案 0 :(得分:0)

阅读文档和示例。您在SMTPSecure = 'tls'中使用Port = 465。有充分的文件证明,这种组合将不起作用。更改为ssl或端口587,但不能同时更改两者。

相关问题