這篇文章主要介紹了CodeIgniter使用smtp服務發送html郵件的方法,涉及CodeIgniter中email類的使用技巧,需要的朋友可以參考下
本文實例講述了CodeIgniter使用smtp服務發送html郵件的方法。分享給大家供大家參考。具體如下:
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封殺掉 :(
希望本文所述對大家基于CodeIgniter的php程序設計有所幫助。
新聞熱點
疑難解答