PHP 邮件程序 "Could not connect to SMTP host."

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"(除非你有自己的证书。)

我刚刚试了一下,成功了。