《PHP編程:CodeIgniter基于Email類發郵件的方法》要點:
本文介紹了PHP編程:CodeIgniter基于Email類發郵件的方法,希望對您有用。如果有疑問,可以聯系我們。
本文實例講述了CodeIgniter基于Email類發郵件的辦法.分享給大家供大家參考,具體如下:PHP編程
CodeIgniter擁有功能強大的Email類.以下為利用其發送郵件的代碼.PHP編程
關于CI的Email類的詳情請參考:http://codeigniter.org.cn/user_guide/libraries/email.htmlPHP編程
文件路徑為/application/controllers/welcome.phpPHP編程
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this->load->library('email'); //加載CI的email類 //以下設置Email參數 $config['protocol'] = 'smtp'; $config['smtp_host'] = 'smtp.163.com'; $config['smtp_user'] = 'fanteathy'; $config['smtp_pass'] = '******'; $config['smtp_port'] = '25'; $config['charset'] = 'utf-8'; $config['wordwrap'] = TRUE; $config['mailtype'] = 'html'; $this->email->initialize($config); //以下設置Email內容 $this->email->from('fanteathy@163.com', 'fanteathy'); $this->email->to('517081935@qq.com'); $this->email->subject('Email Test'); $this->email->message('<font color=red>Testing the email class.</font>'); $this->email->attach('application\controllers\1.jpeg'); //相對于index.php的路徑 $this->email->send(); //echo $this->email->print_debugger(); //返回包含郵件內容的字符串,包括EMAIL頭和EMAIL正文.用于調試. } }
在加載Email類之后需要配置Email參數.配置完成之后使用PHP編程
$this->email->initialize($config)
來初始化參數.再設置郵件的內容,最后調用PHP編程
$this->email->send()
發送郵件.其中要注意如果添加附件時,附件的地址是相對CI根目錄下的index.php的路徑.運行結果如下:PHP編程
PHP編程
更多關于CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》PHP編程
希望本文所述對大家基于CodeIgniter框架的PHP程序設計有所贊助.PHP編程
維易PHP培訓學院每天發布《PHP編程:CodeIgniter基于Email類發郵件的方法》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。