程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> CodeIgniter基於Email類發郵件的方法,codeigniteremail

CodeIgniter基於Email類發郵件的方法,codeigniteremail

編輯:關於PHP編程

CodeIgniter基於Email類發郵件的方法,codeigniteremail


本文實例講述了CodeIgniter基於Email類發郵件的方法。分享給大家供大家參考,具體如下:

CodeIgniter擁有功能強大的Email類。以下為利用其發送郵件的代碼。

關於CI的Email類的詳情請參考: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類
    //以下設置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('[email protected]', 'fanteathy');
    $this->email->to('[email protected]');
    $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參數。配置完成之後使用

$this->email->initialize($config)

來初始化參數。再設置郵件的內容,最後調用

$this->email->send()

發送郵件。其中要注意如果添加附件時,附件的地址是相對CI根目錄下的index.php的路徑。運行結果如下:

更多關於CodeIgniter相關內容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php日期與時間用法總結》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家基於CodeIgniter框架的PHP程序設計有所幫助。

您可能感興趣的文章:

  • CodeIgniter使用smtp服務發送html郵件的方法
  • codeigniter發送郵件並打印調試信息的方法
  • Codeigniter發送郵件的方法
  • Codeigniter實現發送帶附件的郵件
  • CodeIgniter分頁類pagination使用方法示例
  • CodeIgniter輔助之第三方類庫third_party用法分析
  • CodeIgniter擴展核心類實例詳解
  • CI(Codeigniter)的Setting增強配置類實例
  • php實現仿寫CodeIgniter的購物車類
  • Codeigniter的dom類用法實例
  • Codeigniter購物車類不能添加中文的解決方法

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved