//找回密碼
public function reset(){
if(IS_POST){
$username=I(\'post.username\');
$email=I(\'post.email\');
//查詢賬號(hào)是否存在
$info= M(\'member\')->where(array(\'username\'=>$username))->field(\'id,email,username,password\')->find();
if($info[\'id\']==null){
$this->error(\'此賬號(hào)不存在\');
}
//判斷是否填郵箱
if($info[\'email\']!=$email){
$this->error(\'郵箱跟您注冊(cè)的郵箱不一致\');
}
$key = md5 ( $info [\'username\'] . \'+\' . $info [\'password\'] ); // MD5不可逆,驗(yàn)證$string中username,防止URL更改username
$string = base64_encode ( $info [\'username\'] . \'+\' . $key ); // 加密,可解密
$time = time ();
$code=md5 ( \'mytime\'.$time );
// 生成URL
$findpwd = $_SERVER [\'HTTP_HOST\'] . U(\'Change/changePassword\' ,array(\'key\'=>$key,\'info\'=>$string,\'time\'=>$time,\'code\'=>$code)); // code是用來(lái)檢驗(yàn)time是否有修改過(guò)
// 調(diào)用發(fā)送郵件函數(shù)
$username = $info [\'username\'];
$title="找回密碼";
$content="<h3>親愛(ài)的:$username 用戶</h3>
<br><br>請(qǐng)點(diǎn)擊:<a href=\'http://$findpwd\'>找回密碼</a>
<br><br><h4>請(qǐng)及時(shí)修改密碼</h4>
<br><br><br><h4>有效期30分鐘</h4>
<br><br>";
$to=$info [\'email\'];
$status = $this->send_mail ( $title,$content,$to );
if($status==1){
$this->success ( \'發(fā)送郵件成功...\' , U ( \'Login/index\' ), 2 );
}else{
$this->error ( \'發(fā)送郵件失敗...\');
exit ();
}
}else{
$this->display();
}
}
//發(fā)送郵件
public function send_mail($title, $content,$to, $chart = \'utf-8\', $attachment = \'\') {
//查詢郵箱配置信息
$sys=M(\'sysconfig\')->where(array(\'config_name\'=>\'email\'))->field(\'config_text\')->find();
$sys=unserialize($sys[\'config_text\']);
include \'./ThinkPHP/Library/Vendor/PHPMailer/class.phpmailer.php\';
//class.smtp.php
include \'./ThinkPHP/Library/Vendor/PHPMailer/class.smtp.php\';
$mail = new PHPMailer ();
$mail->CharSet = $chart; // 設(shè)置采用gb2312中文編碼
$mail->isSMTP (); // 設(shè)置采用SMTP方式發(fā)送郵件
$mail->Host = $sys[\'mail_host\']; // 設(shè)置郵件服務(wù)器的地址
$mail->SMTPSecure = \'ssl\';
$mail->CharSet = \'UTF-8\';
$mail->Port = $sys[\'smtp\']; // 設(shè)置郵件服務(wù)器的端口,默認(rèn)為25
$mail->From =$sys[\'mail_from\']; // 設(shè)置發(fā)件人的郵箱地址
$mail->FromName =$sys[\'mail_fromname\']; // 設(shè)置發(fā)件人的姓名
$mail->SMTPAuth = true; // 設(shè)置SMTP是否需要密碼驗(yàn)證,true表示需要
$mail->Username = $sys[\'mail_name\']; // 設(shè)置發(fā)送郵件的郵箱
$mail->Password = $sys[\'mail_password\']; // 設(shè)置郵箱的密碼
$mail->Subject = $title; // 設(shè)置郵件的標(biāo)題
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; // 設(shè)置郵件內(nèi)容
$mail->IsHTML ( true ); // 設(shè)置內(nèi)容是否為html類型
$mail->WordWrap = 50; // 設(shè)置每行的字符數(shù)
// $mail->AddReplyTo ( "地址", "名字" ); // 設(shè)置回復(fù)的收件人的地址
$mail->AddAddress ( $to, "" ); // 設(shè)置收件的地址
if ($attachment != \'\') {
$mail->AddAttachment ( $attachment, $attachment );
}
if ($mail->Send ()) {
//$status1 = "$to" . \' 已投送成功<br />\';
$status = 1;
} else {
//$status2 = "$to" . \' 發(fā)送郵件失敗<br />\';
$status = 0;
}
return $status;
}
文章名稱:基于TP3.2的發(fā)送郵箱做找回密碼
文章分享:http://sd-ha.com/article8/cjsoop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、App開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、服務(wù)器托管、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)