本文實(shí)例講述了codeigniter基于email類發(fā)郵件的方法。分享給大家供大家參考,具體如下:
CodeIgniter擁有功能強(qiáng)大的Email類。以下為利用其發(fā)送郵件的代碼。
關(guān)于CI的Email類的詳情請(qǐng)參考:http://codeigniter.org.cn/user_guide/libraries/email.html
文件路徑為/application/controllers/welcome.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { public function index() { $this->load->library('email'); //加載CI的email類 //以下設(shè)置Email參數(shù) $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); //以下設(shè)置Email內(nèi)容 $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'); //相對(duì)于index.php的路徑 $this->email->send(); //echo $this->email->print_debugger(); //返回包含郵件內(nèi)容的字符串,包括EMAIL頭和EMAIL正文。用于調(diào)試。 } }
在加載Email類之后需要配置Email參數(shù)。配置完成之后使用
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
$this->email->initialize($config)
來初始化參數(shù)。再設(shè)置郵件的內(nèi)容,最后調(diào)用
$this->email->send()
發(fā)送郵件。其中要注意如果添加附件時(shí),附件的地址是相對(duì)CI根目錄下的index.php的路徑。運(yùn)行結(jié)果如下:
更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)