Then, write the following function [php] functionsend_mail ($ to, $ title, $ body) {$ ci & amp; get_instance (); require_once (& amp; #39; phpmailer/class. phpmailer. php & amp; #39;); require_o
Then write the following functions into the helper file:
[Php]
Function send_mail ($ to, $ title, $ body)
{
$ Ci = & get_instance ();
Require_once ('phpmailer/class. phpmailer. php ');
Require_once ('phpmailer/class. smtp. php ');
$ Mail = new PHPMailer (true); // the true param means it will throw throtions on errors, which we need to catch
$ Mail-> IsSMTP (); // telling the class to use SMTP
Try {
$ Mail-> Host = $ ci-> config-> item ('mail _ smtp '); // SMTP server
$ Mail-> SMTPDebug = false; // enables SMTP debug information (for testing)
$ Mail-> SMTPAuth = true; // enable SMTP authentication
$ Mail-> Port = $ ci-> config-> item ('mail _ Port'); // set the SMTP port for the GMAIL server
$ Mail-> Username = $ ci-> config-> item ('mail _ address'); // SMTP account username
$ Mail-> Password = $ ci-> config-> item ('mail _ passwd'); // SMTP account password
$ Mail-> AddAddress (www.2cto.com ,'');
$ Mail-> SetFrom ($ ci-> config-> item ('mail _ address'), $ ci-> config-> item ('mail _ name '));
$ Mail-> Subject = $ title;
$ Mail-> MsgHTML ($ body );
$ Mail-> Send ();
Return true;
} Catch (phpmailerException $ e ){
// Echo $ e-> errorMessage (); // Pretty error messages from PHPMailer
Return false;
} Catch (Exception $ e ){
// Echo $ e-> getMessage (); // Boring error messages from anything else!
Return false;
}
}
Function send_mail ($ to, $ title, $ body)
{
$ Ci = & get_instance ();
Require_once ('phpmailer/class. phpmailer. php ');
Require_once ('phpmailer/class. smtp. php ');
$ Mail = new PHPMailer (true); // the true param means it will throw throtions on errors, which we need to catch
$ Mail-> IsSMTP (); // telling the class to use SMTP
Try {
$ Mail-> Host = $ ci-> config-> item ('mail _ smtp '); // SMTP server
$ Mail-> SMTPDebug = false; // enables SMTP debug information (for testing)
$ Mail-> SMTPAuth = true; // enable SMTP authentication
$ Mail-> Port = $ ci-> config-> item ('mail _ Port'); // set the SMTP port for the GMAIL server
$ Mail-> Username = $ ci-> config-> item ('mail _ address'); // SMTP account username
$ Mail-> Password = $ ci-> config-> item ('mail _ passwd'); // SMTP account password
$ Mail-> AddAddress (www.2cto.com ,'');
$ Mail-> SetFrom ($ ci-> config-> item ('mail _ address'), $ ci-> config-> item ('mail _ name '));
$ Mail-> Subject = $ title;
$ Mail-> MsgHTML ($ body );
$ Mail-> Send ();
Return true;
} Catch (phpmailerException $ e ){
// Echo $ e-> errorMessage (); // Pretty error messages from PHPMailer
Return false;
} Catch (Exception $ e ){
// Echo $ e-> getMessage (); // Boring error messages from anything else!
Return false;
}
}
In addition, write your mailbox configuration items in config
[Php]
$ Config ['mail _ name'] = 'jiao Changyun ';
$ Config ['mail _ passwd'] = 'password ';
$ Config ['mail _ address'] = 'xxxx @ 21cn.com ';
$ Config ['mail _ smtp '] = 'smtp .21cn.com ';
$ Config ['mail _ smtp_port '] = 25;
$ Config ['mail _ name'] = 'jiao Changyun ';
$ Config ['mail _ passwd'] = 'password ';
$ Config ['mail _ address'] = 'xxxx @ 21cn.com ';
$ Config ['mail _ smtp '] = 'smtp .21cn.com ';
$ Config ['mail _ smtp_port '] = 25;
Author: jiaochangyun