phpmailer在服务器上不能正常发送邮件的解决办法

yipeiwu_com4年前服务器

phpmailer本身是一个很不错的开源邮件类,也非常的易用简单,就是偶尔会出现程序上传到服务器上不能发送邮件的情况,在之前也有同学问过我这个问题,当时的时候总是不以为然,今天终于让我碰上了,用phpmailer 在本地测试正常,上传到服务器上就不行了,当然了是用的SMTP方式,最终确定是fsockopen 函数惹的祸,因为安全原因fsockopen 和pfsockopen 经常被服务器端关闭。解决方法如下:

而代之的应该是 stream_socket_client()函数,不过他的参数有一点不一样。

应这样更改phpmailer 的 class.stmp.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

改为

$this->smtp_conn = @stream_socket_client( $host.':'.$port,  // the host of the server
                 $errno,  // error number if any
                 $errstr, // error message if any
                 $tval);  // give up after ? secs

这里 PHP版本应高于 5.0 的,因为较早版本没有stream_socket_client()函数的。
OK ,问题解决了。

相关文章

Python Web程序部署到Ubuntu服务器上的方法

Python Web程序部署到Ubuntu服务器上的方法

在本文记录了我在Ubuntu中部署Flask Web站点的过程, 其中包括用户创建、代码获取、Python3环境的安装、虚拟环境设置、uWSGI启动程序设置,并将Nginx作为前端反向代...

Go语言基于Socket编写服务器端与客户端通信的实例

Go语言基于Socket编写服务器端与客户端通信的实例

在golang中,网络协议已经被封装的非常完好了,想要写一个Socket的Server,我们并不用像其他语言那样需要为socket、bind、listen、receive等一系列操作头疼...

django2+uwsgi+nginx上线部署到服务器Ubuntu16.04

django2+uwsgi+nginx上线部署到服务器Ubuntu16.04

1.前期准备 1.打开Terminal终端,执行以下命令,将项目所需要的依赖包,都记录到一个文件内备用。 pip freeze >requirements.txt 2.将项...

python实现从ftp服务器下载文件的方法

本文实例讲述了python实现从ftp服务器下载文件的方法。分享给大家供大家参考。具体实现方法如下: import ftplib ftp = ftblib.FTP("ftp.your...

php使用socket post数据到其它web服务器的方法

本文实例讲述了php使用socket post数据到其它web服务器的方法。分享给大家供大家参考。具体实现方法如下: function post_request($url, $dat...