PHPMailer是一个非常棒的开源邮件类,使用也非常简单,但是对于虚拟主机来说,往往要受到各种限制。刚才我在虚拟主机上使用PHPMailer就遇到一个“SMTP Error: Could not connect to SMTP host”错误。下面介绍两种解决办法:

这个错误说明虚拟主机不支持PHPMailer默认调用的fsockopen函数,找到class.smtp.php文件,搜索fsockopen,就找到了这样一段代码:

使用stream_socket_client函数

一般fsockopen()被禁,pfsockopen也有可能被禁,所以这里介绍另一个函数stream_socket_client()。

stream_socket_client的参数与fsockopen有所不同,所以代码要修改为:

$this->smtp_conn = stream_socket_client("tcp://".$host.":".$port, $errno,  $errstr,  $tval);

这样就可以了。

SMTP Error: Could not connect to SMTP host的更多相关文章

  1. phpmailer SMTP Error: Could not connect to SMTP host. 错误解决

    今天发邮件遇到了这么一个问题:SMTP Error: Could not connect to SMTP host.在网上找了好多,都不管用.在这里我要提醒大家下 1.确保发送者邮箱密码正确,代码编写 ...

  2. 解决 SMTP Error: Could not connect to SMTP host. 问题

    我在使用PHPmailer发邮件时候,遇到了这个问题“SMTP Error: Could not connect to SMTP host.”,分享一下解决方法. 这个错误是PHP版本7产生的.如果我 ...

  3. 用phpmailer发送邮件提示SMTP Error: Could not connect to SMTP host解决办法

    之前做项目的时候做了一个用phpmailer发送邮件的功能<CI框架结合PHPmailer发送邮件>,昨天步署上线(刚开始用新浪云,嫌贵,换成阿里了),测试的时候,发送邮件却意外报错了.. ...

  4. phpmailer的SMTP ERROR: Failed to connect to server: 10

    请问,我在win7上学习使用phpmailer时,出现这种错误怎么处理啊? SMTP ERROR: Failed to connect to server: (0) SMTP connect() fa ...

  5. 使用phpmailer插件发邮件失败提示:SMTP -> ERROR: Failed to connect to server: Connection timed out (110) smtp connect() failed;

    一个邮件发送问题,整整弄了我一周时间,起因是这样的,之前弄的一个网站,需要在邮箱里面认证之后才可以注册成功.网站上线了差不多一年之后,客户突然跟我说,网站不能注册了,然后我就查看了一下代码. 发现报这 ...

  6. linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误

    转自:https://www.cnblogs.com/raincowl/p/8875647.html //Create a new PHPMailer instance $mail = new PHP ...

  7. 腾讯云服务器SMTP ERROR: Failed to connect to server

    一般邮件发送失败是 1.配置的问题. 2.扩展问题socket/ssl 百度搜出来一般都是以上的解决办法, 但是我这次遇到的不是. 本地可以放到腾讯云服务器就不行了,扩展也都开了. 后来发现是安全组端 ...

  8. javax.mail.MessagingException: Could not connect to SMTP host: smtp.xdf.cn

    1.问题描述:关于使用Java Mail进行邮件发送,抛出Could not connect to SMTP host: xx@xxx.com, port: 25的异常可能: 当我们使用Java Ma ...

  9. Could not connect to SMTP host: smtp.***.com, port: 465, response: -1

    背景 在使用javamail进行邮件发送的时候,报错: Could not connect to SMTP host: smtp.***.com, port: 465, response: -1 原因 ...

随机推荐

  1. phpcms

    phpcms 织梦 帝国cms

  2. iOS On-Demand Resources简单理解

    ios9引入了一个新功能,On-Demand Resources,它是app thinning 的一部分.这个机能简单的说,就是在下载app的时候,app中包含的不重要资源不下载,等到需要时,在由系统 ...

  3. preparestatement可以避免注入

    之所以PreparedStatement能防止注入,是因为它把单引号转义了,变成了\',这样一来,就无法截断SQL语句,进而无法拼接SQL语句,基本上没有办法注入了. 不使用这个,我们一般做查询或更新 ...

  4. MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP)

    MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP) Tue, 03/01/2011 - 18:30 Tweet Development E-Comm ...

  5. Xcode 此证书签发者无效

    1.https://developer.apple.com/certificationauthority/AppleWWDRCA.cer 安装此证书 2.在keychains里选择login,然后点选 ...

  6. [jquery]添加行内容后根据下拉菜单选择内容对比之前已有选项,若有重置再提示

    今天页面上一个添加列内容时,要对选择内容与之前已有选项内容作对比,防止用户重复选择内容 页面HTML代码 <ul class="list-group xj-list-NObor xj- ...

  7. libcpmt.lib 与 msvcprt.lib

    https://msdn.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx

  8. Sublime Text 2 增加python版本

    当系统中装有多个python版本时,Sublime Text 2  使用哪个版本需要手动添加 键入一下内容,path输入python的安转路径 保存至Python27.sublime-build文件 ...

  9. linux安装open block chain

    Compile the source code Step 1. 安装git sudo apt-get install git Step 2. 安装vagrant(ubuntu系统) 下载地址https ...

  10. 用C#通过正则表达式截取字符串中符合条件的子字符串

    仅仅作为简单的记录,不多说直接上代码(仅测试使用): private void Test() { Regex ConnoteA = new Regex("^[a-zA-Z]\\d{8}$&q ...