欢迎各位兄弟 发布技术文章
这里的技术是共享的
(1)服务器不能使用smtp的形式发送邮件
解决办法:很多网站列出的解决办法说是因为smtp大小写的问题,虽然问题的本质不在这里,但确实也需要改这个地方,至于为什么,看下面的操作。
在 class.phpmailer.php 中,将:
1 | function IsSMTP(){ $this ->Mailer= 'smtp' ;} |
改成:
1 | function IsSMTP(){ $this ->Mailer = 'SMTP' ;} |
这个地方的修改不是使用了smtp来发送邮件,而是使用了另外一种方式发送邮件,检查 class.phpmailer.php 文件里面有下面这么一段:
1 | switch ( $this ->Mailer){ |
2 | case 'sendmail' : |
3 | return $this ->SendmailSend( $header , $body ); |
4 | case 'smtp' : //由于SMTP和smtp不相等 所以选择的是下面MailSend发送邮件 并不是使用smtp发送邮件 |
5 | return $this ->SmtpSend( $header , $body ); |
6 | default : |
7 | return $this ->MailSend( $header , $body ); |
8 | } |
(2)Linux主机禁用了fsockopen()函数
国内有很多空间服务商出于安全考虑会禁用服务器的fsockopen函数。
解决方法:
用pfsockopen() 函数代替 fsockopen() ,如果 pfsockopen 函数也被禁用的话,还可换其他可以操作Socket函数来代替, 如stream_socket_client()
在 class.smtp.php 中将 @fsockopen 改成 @pfsockopen
把
1 | $this ->smtp_conn = @ fsockopen ( $host , // the host of the server |
2 | $port , // the port to use |
3 | $errno , // error number if any |
4 | $errstr , // error message if any |
5 | $tval ); // give up after ? secs |
改成:
1 | $this ->smtp_conn = @pfsockopen( $host , // the host of the server |
2 | $port , // the port to use |
3 | $errno , // error number if any |
4 | $errstr , // error message if any |
5 | $tval ); // give up after ? secs |
(3)防火墙安全设置规则,如果以上两种方案都不凑效,那估计是防火墙的规则问题了,可以让服务器管理员去掉所有的防火墙规则,然后测试一下,看是否是这个原因。