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