


CodeIgniter's method of sending emails based on the Email class, codeigniteremail_PHP tutorial
Jul 12, 2016 am 08:55 AMCodeIgniter基于Email類發(fā)郵件的方法,codeigniteremail
本文實例講述了CodeIgniter基于Email類發(fā)郵件的方法。分享給大家供大家參考,具體如下:
CodeIgniter擁有功能強大的Email類。以下為利用其發(fā)送郵件的代碼。
關(guān)于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類 //以下設(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'); //相對于index.php的路徑 $this->email->send(); //echo $this->email->print_debugger(); //返回包含郵件內(nèi)容的字符串,包括EMAIL頭和EMAIL正文。用于調(diào)試。 } }
在加載Email類之后需要配置Email參數(shù)。配置完成之后使用
$this->email->initialize($config)
來初始化參數(shù)。再設(shè)置郵件的內(nèi)容,最后調(diào)用
$this->email->send()
發(fā)送郵件。其中要注意如果添加附件時,附件的地址是相對CI根目錄下的index.php的路徑。運行結(jié)果如下:
更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《php日期與時間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于CodeIgniter框架的PHP程序設(shè)計有所幫助。
您可能感興趣的文章:
- CodeIgniter使用smtp服務(wù)發(fā)送html郵件的方法
- codeigniter發(fā)送郵件并打印調(diào)試信息的方法
- Codeigniter發(fā)送郵件的方法
- Codeigniter實現(xiàn)發(fā)送帶附件的郵件
- CodeIgniter分頁類pagination使用方法示例
- CodeIgniter輔助之第三方類庫third_party用法分析
- CodeIgniter擴展核心類實例詳解
- CI(Codeigniter)的Setting增強配置類實例
- php實現(xiàn)仿寫CodeIgniter的購物車類
- Codeigniter的dom類用法實例
- Codeigniter購物車類不能添加中文的解決方法

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Is the Outlook mail icon missing from Windows 11's Control Panel? This unexpected situation has caused confusion and concern among some individuals who rely on OutlookMail for their communication needs. Why don't my Outlook emails show up in Control Panel? There may be several possible reasons why there are no Outlook mail icons in Control Panel: Outlook is not installed correctly. Installing Office applications from the Microsoft Store does not add the Mail applet to Control Panel. The location of the mlcfg32.cpl file in Control Panel is missing. The path to the mlcfg32.cpl file in the registry is incorrect. The operating system is not currently configured to run this application

If you find that blank pages appear when printing a mail merge document using Word, this article will help you. Mail merge is a convenient feature that allows you to easily create personalized documents and send them to multiple recipients. In Microsoft Word, the mail merge feature is highly regarded because it helps users save time manually copying the same content for each recipient. In order to print the mail merge document, you can go to the Mailings tab. But some Word users have reported that when trying to print a mail merge document, the printer prints a blank page or doesn't print at all. This may be due to incorrect formatting or printer settings. Try checking the document and printer settings and make sure to preview the document before printing to ensure the content is correct. if

PHP sends emails asynchronously: avoid long waits for emails to be sent. Introduction: In web development, sending emails is one of the common functions. However, since sending emails requires communication with the server, it often causes users to wait for a long time while waiting for the email to be sent. In order to solve this problem, we can use PHP to send emails asynchronously to optimize the user experience. This article will introduce how to implement PHP to send emails asynchronously through specific code examples and avoid long waits. 1. Understanding sending emails asynchronously

How to implement custom middleware in CodeIgniter Introduction: In modern web development, middleware plays a vital role in applications. They can be used to perform some shared processing logic before or after the request reaches the controller. CodeIgniter, as a popular PHP framework, also supports the use of middleware. This article will introduce how to implement custom middleware in CodeIgniter and provide a simple code example. Middleware overview: Middleware is a kind of request

PHP email tracking function: understand user behavior and feedback on emails In modern society, email has become an indispensable part of people's daily life and work. For businesses, sending emails is one of the important ways to communicate with customers and promote products or services. However, after an email is sent, how do we know whether it was received, read, or how the user reacted to the content of the email? At this time, the email tracking function becomes particularly important. The email tracking function can help us understand user behavior and feedback on emails

CodeIgniter Middleware: Accelerating Application Responsiveness and Page Rendering Overview: As web applications continue to grow in complexity and interactivity, developers need to use more efficient and scalable solutions to improve application performance and responsiveness. . CodeIgniter (CI) is a lightweight PHP-based framework that provides many useful features, one of which is middleware. Middleware is a series of tasks that are performed before or after the request reaches the controller. This article will introduce how to use

According to news on June 7, technology media AppleInsider published a blog post yesterday, revealing that Apple is developing Project BlackPearl internally, which mainly enhances the email application in iOS18 and macOS15 systems, allowing AI to help users compose and reply to emails. The relevant content is summarized as follows: Enhanced Search Project BlackPearl first enhances email search results, which will display more information from address books, locations and locally stored documents. Smart Replies In addition, the new "Smart Replies" function in the email application will provide appropriate reply content based on the locally running large language model (LLM) Ajax and combined with the context of the email. compose mail

Introduction to the method of using the database query builder (QueryBuilder) in the CodeIgniter framework: CodeIgniter is a lightweight PHP framework that provides many powerful tools and libraries to facilitate developers in web application development. One of the most impressive features is the database query builder (QueryBuilder), which provides a concise and powerful way to build and execute database query statements. This article will introduce how to use Co
