早段时间设置了163邮箱发送没有问题,今天打算换了公司的腾讯企业邮箱,结果发送失败。
开启了打印信息查看问题:
echo $this->email->print_debugger();
发送邮件失败提示
220 smtp.qq.com Esmtp QQ Mail Server
hello:
发生错误,SMTP 错误信息为:
starttls:
发生错误,SMTP 错误信息为:
发生错误,SMTP 错误信息为:
无法使用 PHP SMTP。您的服务器设置禁止使用此方法发送 E-mail。
User-Agent: CodeIgniter
Date: Mon, 7 Sep 2015 14:43:23 +0800
From: "ASDFASDF" <yangxuguang@12301v.com>
Return-Path: <yangxuguang@12301v.com>
To: 564363690@qq.com
Subject: =?UTF-8?Q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?=
Reply-To: "yangxuguang@12301v.com" <yangxuguang@12301v.com>
X-Sender: yangxuguang@12301v.com
X-Mailer: CodeIgniter
X-Priority: 1 (Highest)
Message-ID: <55ed320b474e7@12301v.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_55ed320b4789d"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_55ed320b4789d
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修改密码验证码:
--B_ALT_55ed320b4789d
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
修改密码验证码:
--B_ALT_55ed320b4789d--
后来在网上找到一位遇到同样问题的同志:
http://www.phperstar.com/post/219
关键配置
1.smtp_host服务器地址:smtp.exmail.qq.com
2.默认Email类中
var $newline= "\n";
var $crlf= "\n";
这两项是这样的。在163邮箱中可以通过。 而腾讯邮箱服务器好像不支持,所以就是出现错误的罪魁祸首。把这两项改成:
$config['crlf']="\r\n";
$config['newline']="\r\n";
就完成支持腾讯邮箱服务器了。
这里给出我的完整email.php配置:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//用户代理 'user agent'
$config['useragent'] = 'CodeIgniter';
//mail, sendmail, or smtp 邮件发送协议
$config['protocol'] = 'smtp';
//服务器上 Sendmail 的实际路径。protocol 为 sendmail 时使用
$config['mailpath'] = '/usr/sbin/sendmail';
//smtp服务器地址
//$config['smtp_host'] = 'smtp.163.com';
$config['smtp_host'] = 'smtp.exmail.qq.com';
//smtp用户账户
$config['smtp_user'] = 'yangxuguang@12301v.com';
//smtp用户密码
$config['smtp_pass'] = '******';
//smtp端口
$config['smtp_port'] = 25;
//stmp超时设置
$config['smtp_timeout'] = 5;
//是否启用 SMTP 持久连接
$config['smtp_keepalive'] = FALSE;
//tls or ssl SMTP 加密方式
$config['smtp_crypto'] = 'tls';
//开启自动换行
$config['wordwrap'] = TRUE;
//自动换行时每行的最大字符数
$config['wrapchars'] = 76;
//邮件类型。发送 HTML 邮件比如是完整的网页。请确认网页中是否有相对路径的链接和图片地址,它们在邮件中不能正确显示
$config['mailtype'] = 'html';
//字符集(utf-8, iso-8859-1 等)
$config['charset'] = 'utf-8';
//是否验证邮件地址
$config['validate'] = FALSE;
//Email 优先级. 1 = 最高. 5 = 最低. 3 = 正常
$config['priority'] = 1;
//换行符 这两项千万不能修改 否则腾讯服务器将无法发送
//$config['crlf'] = "\r\n";
//$config['newline']="\r\n";
//启用批量暗送模式
$config['bcc_batch_mode'] = TRUE;
//批量暗送的邮件数
$config['bcc_batch_size'] = 200;