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//below 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 (); Returns a string containing the contents of the message, including the email header andEmail text.
For debugging. }
}
After loading the email class, you need to configure the email parameters. After the configuration is complete, use the $this->email->initialize ($config) function to initialize the parameters. The contents of the message are then set, and the Last Call $this->email->send () sends 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: