首页 文章

PHPMailer“无法连接到SMTP主机 . ”

提问于
浏览
-1

我正在尝试使用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';
}
?>

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

1 回答

  • 1

    这是 $mail->SMTPSecure = 'tls';tsl

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

    我刚尝试过并且工作过 .

相关问题