CodeIgniter is based on the e-mail method, codeigniteremail. CodeIgniter is based on the e-mail method. codeigniteremail this article describes how CodeIgniter sends emails by Email. For your reference, refer to C CodeIgniter's Email-based method, codeigniteremail.
This example describes how CodeIgniter sends emails by Email. 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: