CodeIgniter 使用 Email 类通过 QQ 企业邮箱发送邮件

最近要要用到发邮件这个功能,并且正在熟悉 CodeIgniter 这个框架,所以准备用 CodeIgniter 的 Email 类发邮件。

首先编程环境为 wamp,按照网上的案例没有一个发送成功的,我开始以为是我的电脑没装邮件服务,可是不对啊,我用的是第三方的邮件服务,我不需要装了吧。后来有以为是 SSL 的问题设置代理,还是没用。

我想算了用其它的试试 PHPMailer 和 ZEND 的 mail 类都可以发送成功,这时我感觉应该是我配置错了。

后来在国外一个贴子上发现了原因。

是因为 “电子邮件的标准格式 (RFC 822)”的原因,Codeigniter 中用的是 \n 而 QQ 企业邮箱用的是 \r\n,遵守 RFC 822。

完整代码如下

$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.exmail.qq.com';
$config['smtp_user'] = 'services@fbzl.org';
$config['smtp_pass'] = '******';
$config['smtp_crypto']= "ssl";
$config['validate'] = false;
$config['smtp_port'] = 465;
$config['charset'] = 'utf-8';
$config['wordwrap'] = true;
$config['mailtype'] = 'html';
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$this->email->initialize($config);

$this->email->from('services@fbzl.org','services@fbzl.org');
$this->email->to('services@fbzl.org'); 
$this->email->subject('Email Test');
$this->email->message('Testing the email class.'); 
$this->email->send();

echo $this->email->print_debugger();`
除非注明, 风波竹林 文章均为原创,转载请以链接形式标明本文地址
本文地址: https://blog.fbzl.org/codeigniter使用email类通过qq企业邮箱发送邮件/

发表评论