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

yipeiwu_com6年前服务器

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中SocketServer 实现客户端与服务器间非阻塞通信

利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信。 首先,先了解下SocketServer模块中可供使用的类: BaseServer:包含服务器的核心功能与混合...

php保存任意网络图片到服务器的方法

本文实例讲述了php保存任意网络图片到服务器的方法。分享给大家供大家参考。具体分析如下: 任意指定一个网络图片地址,通过这个函数下载到本地服务器 <?php funct...

深入Memcache的Session数据的多服务器共享详解

一相关介绍1.memcache + memcache的多服务器数据共享的介绍,请参见http://www.guigui8.com/index.php/archives/206.html2...

PHP 实现文件分片上传的实例代码

PHP用超级全局变量数组$_FILES来记录文件上传相关信息的。file_uploads=on/off是否允许通过http方式上传文件max_execution_time=30允许脚本最大执行时间,超...

python修改FTP服务器上的文件名

python修改FTP服务器上的文件名,具体代码如下所示: #-*- coding:utf-8 -*- #修改ftp服务器上的文件名 from ftplib import FTP d...