发送邮件出现Could not connect to SMTP host的解决办法
发送邮件出现“不能连接SMTP服务器.”(Error: Could not connect to SMTP host)的原因是fsockopen()被禁用。
如果服务器禁用了fsockopen()函数就会导致PHPmailer连接远程SMTP服务器就会出现上述错误。
下面给出解决方法:
如果是自己的服务器,请直接编辑php.ini在disable_function中找到fsockopen并删除,重启php试试吧。
如果无法更改php.ini,请用pfsockopen()函数直接替换掉 fsockopen()
如果pfsockopen函数被禁用的话,换其他可以操作Socket函数来代替, 如stream_socket_client()
举例wordpress发送邮件:
找到wp-includes/class.smtp.php 文件
把
@fsockopen 改成 @pfsockopen
[php]$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[/php]
改成
[php]$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[/php]