CodeIgniter 配置使用smtp服務發送html郵件
來源:程序員人生 發布時間:2014-09-17 13:11:10 閱讀次數:3819次
codeigniter 提供的email類,用于發送郵件,
wiki地址: http://codeigniter.org.cn/user_guide/libraries/email.html
實際開發中遇到以下幾個問題,總結一下:
1. wiki中說明是可以將配置文件單獨提出來,email.php 放置到config文件夾下,
對于email.php 的配置,需要說明的幾點:
1) 一般測試使用的smtp服務,如126、163 的郵箱均采用此協議,故 protocol 選擇 smtp
2) 企業營銷郵件一般都是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) 發送的html 屬性值使用的html,需要處理一下
$send_msg = str_replace(""", "", $msg);
$this->email->message($send_msg);
3) 開發時,建議打開debug信息,因為如果你頻繁使用126的郵箱對外發送郵件,
一來可能會被認為是垃圾郵件,更主要的是可能被126封殺掉 :(
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈