This article gives an example of CodeIgniter email based on email class. Share to everyone for your reference, specific as follows:
CodeIgniter has a powerful email class. The following is the code that uses it to send mail.
For more information on CI email class please refer to: http://codeigniter.org.cn/user_guide/libraries/email.html
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 CI Email class
The following set the email parameter $config [' protocol '] = ' smtp ';
$config [' smtp_host '] = ' smtp.163.com ';
$config [' smtp_user '] = ' fanteathy ';
$config [' smtp_pass '] = ' Hu Jintao ';
$config [' smtp_port '] = ' 25 ';
$config [' charset '] = ' utf-8 ';
$config [' wordwrap '] = TRUE;
$config [' mailtype '] = ' html ';
$this->email->initialize ($config);
The following settings email content $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 email class.</font> '); $this->email->attach (' application\controllers\1.jpeg ');
The path $this->email->send () relative to the index.php; echo $this->email->print_debugger (); Return contains message contentsstrings, including email headers and email text.
For debugging.
}
}
After loading the email class, you need to configure the email parameters. Use after configuration is complete
$this->email->initialize ($config)
To initialize the parameters. Then set the contents of the message, and finally call
Send the message. Note that if you add an attachment, the address of the attachment is the path to the index.php in the relative CI root directory. The results of the operation are as follows:
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design based on CodeIgniter framework.