Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPMailer";无法连接到SMTP主机。”;_Php_Email_Smtp_Phpmailer - Fatal编程技术网

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

PHPMailer";无法连接到SMTP主机。”;,php,email,smtp,phpmailer,Php,Email,Smtp,Phpmailer,我正在尝试使用PHPMailer(SMTP)发送邮件。 顺便说一句:邮件服务器由switchplus.ch托管 但如果我尝试发送邮件,我会收到以下错误:“SMTP错误:无法连接到SMTP主机。 " 发送邮件的PHP代码: <?php require './mail/PHPMailerAutoload.php'; $mail = new PHPMailer; $mail->SMTPDebug = 3; // Enable

我正在尝试使用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”(当然,除非您有自己的证书)

我只是尝试了一下,然后就成功了。

在发布前搜索(这至少打开了800次),然后阅读。