Home  >  Article  >  Backend Development  >  thinkphp实现发送邮件密码找回功能实例_php实例

thinkphp实现发送邮件密码找回功能实例_php实例

WBOY
WBOYOriginal
2016-05-16 20:29:24963browse

本文实例讲述了thinkphp实现发送邮件密码找回功能的方法。分享给大家供大家参考。具体实现方法如下:

首先下载mail.class.php类文件,配置文件中定义下列参数:

复制代码 代码如下:
'MAIL_ADDRESS' => 'ivzhu@qq.com', // 邮箱地址 
'MAIL_SMTP' => 'smtp.qq.com', // 邮箱SMTP服务器 
'MAIL_LOGINNAME' => 'mail@qq.com', // 邮箱登录帐号 
'MAIL_PASSWORD' => '123456', // 邮箱密码 
'MAIL_CHARSET' => 'UTF-8', // 编码 
'MAIL_AUTH' => true, // 邮箱认证 
'MAIL_HTML' => true, // true HTML格式 false TXT格式

在tp项目org中放入mail.class.php,使用时候引入 import('@.ORG.Mail');
复制代码 代码如下:
public function index(){ 
    import('@.ORG.Mail'); 
    //SendMail('admin@waikucms.com','邮件标题','邮件正文','歪酷CMS管理员'); 
//解释下参数: 参数1---目标邮箱, 参数2----邮件标题,参数三--邮件正文,参数四---发件人名称; 
    $content=md5(time()); 
    session($content,$content); 
    $content=C('localurl').'/index.php'.U('Mail/index',array('res'=>$content)); 
    if(SendMail('aa@qq.com','nihao邮件标题',$content,'unphp')){ 
    echo 'chengong'; 
    }else{ 
    echo 'shibai'; 
    } 
$this->display(); 
}

另一个页面接受参数res:
复制代码 代码如下:
public function index(){ 
header("Content-type: text/html; charset=utf-8");  
$res=I('res'); 
echo $res; 
if(session($res)==$res){ 
echo '密码找回成功'; 
session($res,null); 
}else{ 
echo '已经过期'; 

}

希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn