PHPMailer “无法连接到 SMTP 主机”


PHPMailer "Could not connect to SMTP host."

我正在尝试使用 PHPMailer (SMTP) 发送邮件。
顺便说一句:邮件服务器由 switchplus.ch 托管...

但是,如果我尝试发送邮件,则会收到以下错误:"SMTP错误:无法连接到SMTP主机。'"

用于发送邮件的 PHP 代码:

<?php
require './mail/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.lordsofmahlstrom.li';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'support@lordsofmahlstrom.li';                 // SMTP username
$mail->Password = 'secredPassword';                           // SMTP password
$mail->SMTPSecure = 'tsl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom('support@lordsofmahlstrom.li', 'Support');
$mail->addAddress('test@test.com', 'Tester');     // Add a recipient
$mail->addReplyTo('support@lordsofmahlstrom.li', 'Support');
$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';
if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

有谁知道,我做错了什么?

$mail->SMTPSecure = 'tls';tsl

此外,如果要加密,则必须连接到主机"smtp.mail-ch.ch"(当然,您有自己的证书除外。

我只是尝试了一下并工作了。