发布时间:2015-05-27 19:33:44作者:知识屋
然后在helper文件里 写入如下函数
[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 exceptions 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.zhishiwu.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 exceptions 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.zhishiwu.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;
}
}
另外在config里写入你的邮箱配置项
[php]
$config['mail_name']='焦常云';
$config['mail_passwd']='password';
$config['mail_address']='xxxx@21cn.com';
$config['mail_smtp']='smtp.21cn.com';
$config['mail_smtp_port']=25;
$config['mail_name']='焦常云';
$config['mail_passwd']='password';
$config['mail_address']='xxxx@21cn.com';
$config['mail_smtp']='smtp.21cn.com';
$config['mail_smtp_port']=25;
作者:jiaochangyun
如何对PHP文件进行加密方法 PHP实现加密的几种方式介绍
php生成圆角图片的方法 电脑中php怎么生成圆角图片教程
用PHP构建一个留言本方法步骤 php怎么实现留言板功能
php中三元运算符用法 php中的三元运算符使用说明
php文件如何怎么打开方式介绍 php文件用什么打开方法
PHP怎么插入数据库方法步骤 php编程怎么导入数据库教程
如何安装PHPstorm并配置方法教程 phpstorm安装后要进行哪些配置
PHP 获取远程文件大小的3种解决方法 如何用PHP获取远程大文件的大小
20个实用PHP实例代码 php接口开发实例代码详细介绍
如何架设PHP服务器方法步骤 怎么搭建php服务器简单教程