SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could
邮件在发送的时候出现SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could……错误,本以为是SMTP邮局的问题,换了一家邮局还是这个错误,又从文件权限查找,无解啊,度娘了一下,发现是某个函数被禁用了,额,以前好好的,什么时候被禁了……
解决方法
SMTP Error: Could not connect to SMTP host”错误。下面介绍两种解决办法:
这个错误说明虚拟主机不支持PHPMailer默认调用的fsockopen函数,找到class.smtp.php文件,搜索fsockopen,就找到了这样一段代码:
// connect to the smtp server
$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方法1:将fsockopen函数替换成pfsockopen函数
因为pfsockopen的参数与fsockopen基本一致,所以只需要将@fsockopen替换成@pfsockopen就可以了。
方法2:使用stream_socket_client函数
一般fsockopen()被禁,pfsockopen也有可能被禁,所以这里介绍另一个函数stream_socket_client()。
stream_socket_client的参数与fsockopen有所不同,所以代码要修改为:
$this->smtp_conn = stream_socket_client(“tcp://”.$host.”:”.$port, $errno, $errstr, $tval);
这样就可以了。
本文出自E星期五的博客,转载时请注明出处及相应链接。
本文永久链接: https://exqw.com/archives/368.html