本文实例讲述了thinkphp实现发送邮件密码找回功能的方法。分享给大家供大家参考。具体实现方法如下:
首先下载mail.class.php类文件,配置文件中定义下列参数:
'MAIL_ADDRESS' => '[email protected]', // 邮箱地址 <br />'MAIL_SMTP' => 'smtp.qq.com', // 邮箱SMTP服务器 <br />'MAIL_LOGINNAME' => '[email protected]', // 邮箱登录帐号 <br />'MAIL_PASSWORD' => '123456', // 邮箱密码 <br />'MAIL_CHARSET' => 'UTF-8', // 编码 <br />'MAIL_AUTH' => true, // 邮箱认证 <br />'MAIL_HTML' => true, // true HTML格式 false TXT格式
在tp项目org中放入mail.class.php,使用时候引入 import(‘@.ORG.Mail’);
public function index(){ <br /> import('@.ORG.Mail'); <br /> //SendMail('[email protected]','邮件标题','邮件正文','歪酷CMS管理员'); <br />//解释下参数: 参数1---目标邮箱, 参数2----邮件标题,参数三--邮件正文,参数四---发件人名称; <br /> $content=md5(time()); <br /> session($content,$content); <br /> $content=C('localurl').'/index.php'.U('Mail/index',array('res'=>$content)); <br /> if(SendMail('[email protected]','nihao邮件标题',$content,'unphp')){ <br /> <p style="color:transparent">本文来源gao!%daima.com搞$代*!码$网3</p><strong>搞代gaodaima码</strong>echo 'chengong'; <br /> }else{ <br /> echo 'shibai'; <br /> } <br />$this->display(); <br />}
另一个页面接受参数res:
public function index(){ <br />header("Content-type: text/html; charset=utf-8"); <br />$res=I('res'); <br />echo $res; <br />if(session($res)==$res){ <br />echo '密码找回成功'; <br />session($res,null); <br />}else{ <br />echo '已经过期'; <br />} <br />}
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。