好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PHPMailer错误SMTP Error: Could not connect to SMTP h

PHPMailer是一个非常棒的开源邮件类,使用也非常简单,但是对于虚拟主机来说,往往要受到各种限制。刚才我在虚拟主机上使用 PHPMailer就遇到一个“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);

查看更多关于PHPMailer错误SMTP Error: Could not connect to SMTP h的详细内容...

  阅读:1427次