【PHPmailer】发送邮件 出现无法连接服务器、函数 fsockopen()被禁用 解决办法 Subject 和 收件人重复
2012-10-12 15:49
1011 查看
网上资料
------------------------------------------------------------------------------------------------------
发现使用PHPmailer发送邮件不成功,提示“不能连接SMTP服务器.”(Error: Could not connect to SMTP host)。
找了很多的方法花费了很多的时间都是出现Could not connect to SMTP host 很是郁闷,所以一直也没有回复大家的评论!~后来找到了一种解决办法就是 服务器发送邮件出现Could not connect to SMTP host错误 解决办法 后来证明是错误的!
我发现并不是因为修改了smtp为SMTP之后却能够发送邮件,这个并不是因为有些邮件服务器不能接受smtp的原因,而并不是使用了smtp来发送邮件,PHPmailer里有一个判断的函数,
public function IsSMTP() {
$this->Mailer = 'SMTP';
}
switch($this->Mailer) {
case 'sendmail':
return $this->SendmailSend($header, $body);
case 'smtp'://由于SMTP和smtp不相等 所以选择的是下面MailSend发送邮件 并不是使用smtp发送邮件
return $this->SmtpSend($header, $body);
default:
return $this->MailSend($header, $body);
虽然可以连接上服务器了,但是邮件一直被QQ当作是垃圾邮件屏蔽了! 主题重复了两次,收件人也是重复了两次!
很是郁闷,由是一番的捣鼓!百度发现了问题所在
Linux主机禁用了fsockopen()函数
国内有很多idc禁用了fsockopen函数。据说是出于安全原因。
不过,就目前收集到的资料来看,fsockopen函数在安全上隐患只出现在Windows平台上,或许对其他平台也有影响,还没有找到fsockopen函数在Linux主机安全方面的利用方法。
解决方案:
用pfsockopen()函数直接替换掉 fsockopen()
如果pfsockopen函数被禁用的话,换其他可以操作Socket函数来代替, 如stream_socket_client()
class.smtp.php 中@fsockopen 改成 @pfsockopen
把
$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
// verify we connected properly
改成
$this->smtp_conn = @pfsockopen($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
// verify we connected properly
------------------------------------------------------------------------------------------------------
自己 解决 Subject 和 收信人重复的问题
class.phpmailer.php
1. 下面 To: 的内容加到 head变量里面的注销掉
/*
*/
2. 下面 Subject: 的内容加到 head变量里面的注销掉
/*
*/
------------------------------------------------------------------------------------------------------
发现使用PHPmailer发送邮件不成功,提示“不能连接SMTP服务器.”(Error: Could not connect to SMTP host)。
找了很多的方法花费了很多的时间都是出现Could not connect to SMTP host 很是郁闷,所以一直也没有回复大家的评论!~后来找到了一种解决办法就是 服务器发送邮件出现Could not connect to SMTP host错误 解决办法 后来证明是错误的!
我发现并不是因为修改了smtp为SMTP之后却能够发送邮件,这个并不是因为有些邮件服务器不能接受smtp的原因,而并不是使用了smtp来发送邮件,PHPmailer里有一个判断的函数,
public function IsSMTP() {
$this->Mailer = 'SMTP';
}
switch($this->Mailer) {
case 'sendmail':
return $this->SendmailSend($header, $body);
case 'smtp'://由于SMTP和smtp不相等 所以选择的是下面MailSend发送邮件 并不是使用smtp发送邮件
return $this->SmtpSend($header, $body);
default:
return $this->MailSend($header, $body);
虽然可以连接上服务器了,但是邮件一直被QQ当作是垃圾邮件屏蔽了! 主题重复了两次,收件人也是重复了两次!
很是郁闷,由是一番的捣鼓!百度发现了问题所在
Linux主机禁用了fsockopen()函数
国内有很多idc禁用了fsockopen函数。据说是出于安全原因。
不过,就目前收集到的资料来看,fsockopen函数在安全上隐患只出现在Windows平台上,或许对其他平台也有影响,还没有找到fsockopen函数在Linux主机安全方面的利用方法。
解决方案:
用pfsockopen()函数直接替换掉 fsockopen()
如果pfsockopen函数被禁用的话,换其他可以操作Socket函数来代替, 如stream_socket_client()
class.smtp.php 中@fsockopen 改成 @pfsockopen
把
$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
// verify we connected properly
改成
$this->smtp_conn = @pfsockopen($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
// verify we connected properly
------------------------------------------------------------------------------------------------------
自己 解决 Subject 和 收信人重复的问题
class.phpmailer.php
1. 下面 To: 的内容加到 head变量里面的注销掉
/*
// To be created automatically by mail() if($this->Mailer != 'mail') { if ($this->SingleTo === true) { foreach($this->to as $t) { $this->SingleToArray[] = $this->AddrFormat($t); } } else { if(count($this->to) > 0) { $result .= $this->AddrAppend('To', $this->to); } elseif (count($this->cc) == 0) { $result .= $this->HeaderLine('To', 'undisclosed-recipients:;'); } } }
*/
2. 下面 Subject: 的内容加到 head变量里面的注销掉
/*
// mail() sets the subject itself if($this->Mailer != 'mail') { $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject))); }
*/
相关文章推荐
- 空间商关闭fsockopen和pfsockopen函数导致phpcms 无法发送邮件的解决办法
- 浅析虚拟主机服务器php fsockopen函数被禁用的解决办法
- 服务器发送邮件出现Could not connect to SMTP host错误 解决办法
- 登录ftp服务器出现响应: 530 Login incorrect. 错误: 严重错误: 无法连接到服务器的解决办法
- 浅析虚拟主机服务器php fsockopen函数被禁用的解决办法
- PHPMailer发送邮件出现Permission denied的解决办法
- Windows Server 2003 使用vSphere5.5连接ESXI5.5 “客户端无法向服务器发送完整的请求” 的解决办法
- 在服务器上用PHPMAIL发送邮件出现Could not connect to SMTP host错误 解决办法
- phpmailer在服务器上不能正常发送邮件的解决办法
- WordPress ”无法发送电子邮件,可能原因:您的主机禁用了mail()函数“的解决办法
- Godaddy服务器发送邮件出现Could not connect to SMTP host错误 解决办法
- Exchange无法发送邮件 未找到匹配的连接器来路由外部收件人解决办法
- 连接PHPmyadmin是出现#2003 – 服务器没有响应 MySQL 无法启动的解决办法
- wordpress无法发送电子邮件。您的主机禁用了 mail() 函数解决办法!
- 用CSMTP类发送邮件出现无法连接服务器的问题
- Windows Server 2003 使用vSphere5.5连接ESXI5.5 “客户端无法向服务器发送完整的请求” 的解决办法
- 打开office出现错误:向程序发送命令时出现问题 无法更改 中注册的office 加载项的连接状态 解决办法
- Oracle10g出现Enterprise Manager 无法连接到数据库实例解决办法
- Domino服务器宕机后无法启动的解决办法——仅出现版本信息
- centos使用phpmailer发送邮件失败的解决办法