Search code examples
phpemailsmtpphpmailer

PHPMailer "Could not connect to SMTP host."


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 = '[email protected]';                 // 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('[email protected]', 'Support');
$mail->addAddress('[email protected]', 'Tester');     // Add a recipient
$mail->addReplyTo('[email protected]', '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?


Solution

  • 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.