CodeIgniter 配置使用smtp服務(wù)發(fā)送html郵件
來源:程序員人生 發(fā)布時間:2014-09-17 13:11:10 閱讀次數(shù):3827次
codeigniter 提供的email類,用于發(fā)送郵件,
wiki地址: http://codeigniter.org.cn/user_guide/libraries/email.html
實際開發(fā)中遇到以下幾個問題,總結(jié)一下:
1. wiki中說明是可以將配置文件單獨提出來,email.php 放置到config文件夾下,
對于email.php 的配置,需要說明的幾點:
1) 一般測試使用的smtp服務(wù),如126、163 的郵箱均采用此協(xié)議,故 protocol 選擇 smtp
2) 企業(yè)營銷郵件一般都是html的,此時,需要配置mailtype 為 html
示例下我寫的email.php 配置文件:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Email Config
|--------------------------------------------------------------------------
| by chaichunyan
|
*/
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.126.com';
$config['smtp_user'] = 'xxx@126.com';
$config['smtp_pass'] = 'xxx';
$config['smtp_port'] = '25';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
2) 發(fā)送的html 屬性值使用的html,需要處理一下
$send_msg = str_replace(""", "", $msg);
$this->email->message($send_msg);
3) 開發(fā)時,建議打開debug信息,因為如果你頻繁使用126的郵箱對外發(fā)送郵件,
一來可能會被認為是垃圾郵件,更主要的是可能被126封殺掉 :(
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈