网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2025/3/15 浏览:3 次 )

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 "htmlcode">
$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 ,问题解决了。

上一篇:PHP中的插件机制原理和实例
下一篇:php去掉URL网址中带有PHPSESSID的配置方法
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。