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

Irina ·
更新时间:2024-09-21
· 633 次阅读

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

您可能感兴趣的文章:PHPMailer使用教程(PHPMailer发送邮件实例分析)PHPMailer邮件类利用smtp.163.com发送邮件方法phpmailer简单发送邮件的方法(附phpmailer源码下载)使用php发送有附件的电子邮件-(PHPMailer使用的实例分析)Linux服务器下PHPMailer发送邮件失败的问题解决PHPMailer邮件发送的实现代码PHPMailer发送HTML内容、带附件的邮件实例163的邮件用phpmailer发送(实例详解)PHP使用PHPMailer发送邮件的简单使用方法php5.5使用PHPMailer-5.2发送邮件的完整步骤



发送邮件 phpmailer 服务器 邮件

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章