使用php发送有附件的电子邮件-(PHPMailer使用的实例分析)


http://xiazai.phpstudy.net/201304/yuanma/PHPMailer_phpstudynet.rar
另外,将当时出现的问题所收录的内容整理如下:

1、Error: Could not connect to SMTP host
原因1:不邮邮件系统要求的smtp请求不同一,但是都允许大写,有些不支持小写,比如网易,腾讯的邮箱。(至于是不是这样,我没测试过,反正都改为大写,也不影响)

解决方法:

复制代码 代码如下:

public function IsSMTP() {
  $this->Mailer ='SMTP'; // 将smtp ->SMTP ;即原来是小写,现在大写。
}

// Choose the mailer and send through it
switch($this->Mailer) {
  case 'sendmail':
    return $this->SendmailSend($header, $body);
  case 'SMTP'://同样 将smtp ->SMTP ;即原来是小写,现在大写。
    return $this->SmtpSend($header, $body);
  case 'mail':
  default:
    return $this->MailSend($header, $body);
}


2、SMTP Error: Could not connect to SMTP host
原因:有的虚拟主机,或服务器,为了安全起见屏蔽了“fsockopen()函数”导致无法发送邮件

解决方法:

启用fsockopen函数

首先,在php.ini中去掉下面的两个分号

;extension=php_sockets.dll

;extension=php_openssl.dll

 替换fsockopen函数

可以将class.smtp.php文件中fsockopen函数换成pfsockopen函数


3、Could not instantiate mail function
原因:

设置的参数不正确,我使用了gmail做一些基本测试,需要在次设置其他参数。

解决方法:

$mail->SMTPSecure = ‘tls'; //只需要加上这句

注:这种错误我没碰到过,所以在上面的例子中,这个内容我是加了注释的。如果碰到这种错误的,可以使用这句试试。


« 
» 

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3