CodeIgniter Email-Based Method _ php instance

Source: Internet
Author: User
This article mainly introduces CodeIgniter's e-mail-based method, and analyzes the use skills of CodeIgniter in calling the Email class provided by CI in combination with examples, for more information about CodeIgniter, see the following example. We will share this with you for your reference. The details are as follows:

CodeIgniter has a powerful Email class. The following code uses it to send Emails.

For more information about the CI Email class, see: http://codeigniter.org.cn/user_guide/libraries/email.html

The file path is/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 '); // load the CI email class. // set the email parameter $ 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 ['wordwre'] = TRUE; $ config ['mailtype'] = 'html'; $ this-> email-> initialize ($ config ); // set the Email content $ this-> email-> from ('fanathy @ 163.com ', 'fanathy '); $ this-> email-> to ('1970 @ qq.com '); $ this-> email-> subject ('email test '); $ this-> email-> message ('testing the email class. '); $ this-> email-> attach ('application \ controllers \ 1.jpeg'); // relative to index. php path $ this-> email-> send (); // echo $ this-> email-> print_debugger ( ); // Returns a string containing the EMAIL content, including the EMAIL header and body. Used for debugging. }}

After loading the Email class, you must configure the Email parameters. Use

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

To initialize parameters. Set the email content, and finally call

$this->email->send()

Send an email. Note that when adding an attachment, the attachment address is relative to the index. php path under the CI root directory. The running result is as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.