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: