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

呼延化
2023-12-01

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

问题解决!

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

 类似资料: