PHPMailer “Could not connect to SMTP host.”

2019-09-20 03:59发布

I'm trying to send a mail with PHPMailer (SMTP).
btw: the mail server is hosted by switchplus.ch...

But if i try to send a mail, I get the following error: "SMTP Error: Could not connect to SMTP host. "

PHP code to send the mail:

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

Does anyone know, what i did wrong?

1条回答
老娘就宠你
2楼-- · 2019-09-20 04:02

it's $mail->SMTPSecure = 'tls'; not tsl

Also, if you want encryption, you have to connect to the host "smtp.mail-ch.ch" (Except of course you have you're own certificate.)

I just tried it and worked.

查看更多
登录 后发表回答