首页 技术 正文
技术 2022年11月19日
0 收藏 406 点赞 4,016 浏览 1520 个字

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

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

我擦,没上线的时候好好的,次次成功,刚开始我以为是smtp地址的问题(我用的163邮箱),后来改成了QQ邮箱,发现还是没有用,没办法,只好问度娘了,后来看着百度上的答案才明白除了google的smtp服务器收到请求”smtp”会接受,其他的服务器就像我用的163,QQ什么的必须要收到大写的 “smtp”请求才行……….emmmmm…..

然后我在class.phpmailer.php中,将

 public function IsSMTP() {
$this->Mailer = 'smtp';
} //改成
public function IsSMTP() {
$this->Mailer = 'SMTP';
}

然后将:

 switch($this->Mailer) {
case 'sendmail':
return $this->SendmailSend($header, $body);
case 'smtp':
return $this->SmtpSend($header, $body);
default:
return $this->MailSend($header, $body);
} //改成
switch($this->Mailer) {
case 'sendmail':
return $this->SendmailSend($header, $body);
case 'SMTP':
return $this->SmtpSend($header, $body);
default:
return $this->MailSend($header, $body);
}

我本来以为这样就可以了,重启Apache,再次测试一下,结果第一个错误是解决了,又出现了一个报错:

Could not instantiate mail function

?????

不知道你们有没有出现,我运气差,只好又求助度娘,终于找到原因:有的虚拟主机,或服务器,为了安全起见屏蔽了“fsockopen()函数”导致无法发送邮件。

下面说一下解决办法:

首先,在php.ini中去掉下面的两个分号

;extension=php_sockets.dll

;extension=php_openssl.dll

之前我用PHPmailer的时候已经去掉了,这里仅仅提示一下。

然后替换fsockopen函数

将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 //fsockopen改为:
$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

这样设置完,我的已经可以成功发送邮件了,如果同样有这方面问题的,可以参考上面的例子试一下。

本文属原创内容,为了尊重他人劳动,转载请注明本文地址:

http://www.cnblogs.com/luokakale/p/7302373.html

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,893