PHPMailer“无法连接到SMTP主机”。 [英] PHPMailer "Could not connect to SMTP host."
本文介绍了PHPMailer“无法连接到SMTP主机”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用PHPMailer(SMTP)发送邮件。
btw:邮件服务器由switchplus.ch ...托管。
I'm trying to send a mail with PHPMailer (SMTP).
btw: the mail server is hosted by switchplus.ch...
但是,如果我尝试发送邮件,我会收到以下错误:SMTP错误:无法连接到SMTP主机
But if i try to send a mail, I get the following error: "SMTP Error: Could not connect to SMTP host. "
PHP代码发送邮件:
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';
}
?>
推荐答案
它的 $ mail-> SMTPSecure ='tls';
不 tsl
此外,如果要加密,则必须连接到主机smtp.mail-ch.ch(除了当然你你有自己的证书。)
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.
这篇关于PHPMailer“无法连接到SMTP主机”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文