无法连接到SMTP主机。讯息无法发送 [英] Could not connect to SMTP host. Message could not be sent

查看:204
本文介绍了无法连接到SMTP主机。讯息无法发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


SMTP错误:无法连接到SMTP主机。讯息无法发送。
Mailer错误:SMTP错误:无法连接到SMTP主机。


我在Stack overflow上发现了另一个答案的许多提示但不行。我试过港口号465/587/65。甚至下面的代码适用于我的本地系统如果我设置端口587.但在服务器,它不工作。

  require('class.phpmailer.php'); 
require('class.smtp.php');

$ mail = new PHPMailer();

$ mail-> IsSMTP();
$ mail-> SMTPSecure =ssl;
$ mail-> SMTPAuth = true;
$ mail-> Host =smtp.gmail.com;
$ mail-> Username =FromEmailId;
$ mail-> Password =密码;
$ mail-> Port = 465;
$ mail-> From =FromEmailId;
$ mail-> AddAddress(ToEmail);
$ mail-> IsHTML(true);
$ mail->主题=这是主题;
$ mail-> Body =这是黑体中的HTML消息正文< b>< / b>;

if(!$ mail-> Send())
{
echo无法发送消息< p>;
echoMailer Error:。 $ MAIL-> ERRORINFO;
退出;
}
echo已发送消息;


解决方案

首先注销您的Gmail帐户



然后打开此网址



点击继续按钮



下一步
更改端口和SMTPsecure

  $ mail-> SMTPSecure =tls; 
$ mail-> Port = 587;


When I sent email from server then it gives me two error -

SMTP Error: Could not connect to SMTP host. Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.

I found many hints on another answers on Stack overflow but doesn't work. I tried port no 465/587/65. Even below code works proper on my local system If i set port 587. But in server, It doesn't work.

require('class.phpmailer.php');
require('class.smtp.php');

$mail = new PHPMailer();

$mail->IsSMTP();      
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com"; 
$mail->Username = "FromEmailId";
$mail->Password = "Password"; 
$mail->Port = 465;
$mail->From = "FromEmailId";
$mail->AddAddress("ToEmail");      
$mail->IsHTML(true);                                  
$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}
echo "Message has been sent";

解决方案

First logout the your gmail account

then open this url use this yrl

click the continue button

Next change the port and SMTPsecure

$mail->SMTPSecure = "tls";
$mail->Port = 587;

这篇关于无法连接到SMTP主机。讯息无法发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆