PHPMailer"无法连接到SMTP主机。"

时间:2016-01-17 02:52:23

标签: php email smtp phpmailer

我尝试使用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 个答案:

答案 0 :(得分:1)

它的$mail->SMTPSecure = 'tls'; 不是tsl

另外,如果你想加密,你必须连接到主机&#34; smtp.mail-ch.ch&#34; (当然,除非您拥有自己的证书。)

我只是尝试过并且工作了。