這篇文章主要介紹了CodeIgniter使用smtp服務(wù)發(fā)送html郵件的方法,涉及CodeIgniter中email類的使用技巧,需要的朋友可以參考下
本文實(shí)例講述了CodeIgniter使用smtp服務(wù)發(fā)送html郵件的方法。分享給大家供大家參考。具體如下:
codeigniter 提供的email類,用于發(fā)送郵件,
wiki地址: http://codeigniter.org.cn/user_guide/libraries/email.html
實(shí)際開發(fā)中遇到以下幾個(gè)問題,總結(jié)一下:
1. wiki中說明是可以將配置文件單獨(dú)提出來,email.php 放置到config文件夾下,
對于email.php 的配置,需要說明的幾點(diǎn):
1) 一般測試使用的smtp服務(wù),如126、163 的郵箱均采用此協(xié)議,故 protocol 選擇 smtp
2) 企業(yè)營銷郵件一般都是html的,此時(shí),需要配置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ā)時(shí),建議打開debug信息,因?yàn)槿绻泐l繁使用126的郵箱對外發(fā)送郵件,
一來可能會被認(rèn)為是垃圾郵件,更主要的是可能被126封殺掉 :(
希望本文所述對大家基于CodeIgniter的php程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答