could not connect to smtp host java_服务器发送邮件出现Could not connect to SMTP host错误的解决办法...

mail()函数被禁用,所以只能找相关的插件来解决。

安装了Configure SMTP插件后,发送测试邮件老是提示“不能连接SMTP服务器.”(Error: Could not connect to SMTP host)郁闷了很久。

上谷歌百度了一遍,有的说是服务器禁用了端口,有的说把class.phpmailer.php中的

function IsSMTP() {

$this->Mailer = 'smtp';

}

改为

function IsSMTP() {

$this->Mailer = 'SMTP';

}

测试以后还是不行,心中郁闷的一米。最后在一篇博客中找到了解决方法,先分享出来让更多遇到同样问题的人能得到帮助!

发送邮件出现“不能连接SMTP服务器.”(Error: Could not connect to SMTP host)的原因是fsockopen()被禁用。

由于国内大多数服务器禁用了mail()函数导致wordpress不能发送邮件,而SMTP 插件则是通过PHPmailer连接远程SMTP服务器来发送邮件,如果服务器禁用了fsockopen()函数就会出现上述错误。

下面给出解决方法:

用pfsockopen()函数直接替换掉 fsockopen()

如果pfsockopen函数被禁用的话,换其他可以操作Socket函数来代替, 如stream_socket_client()

找到wp-includes/class.smtp.php 文件

@fsockopen 改成 @pfsockopen

$this->smtp_conn = @fsockopen(

$host,    // the host of the server

$port,    // the port to use

$errno,   // error number if any

$errstr,  // error message if any

$tval);   // give up after ? secs

// verify we connected properly

改成

$this->smtp_conn = @pfsockopen(

$host,    // the host of the server

$port,    // the port to use

$errno,   // error number if any

$errstr,  // error message if any

$tval);   // give up after ? secs

// verify we connected properly

问题解决!

方法不是原创,只是拿出来分享!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值