public function reset(){
if(IS_POST){
$username=I(\\\’post.username\\\’);
$email=I(\\\’post.email\\\’);
//查詢賬號是否存在
$info= M(\\\’member\\\’)->where(array(\\\’username\\\’=>$username))->field(\\\’id,email,username,password\\\’)->find();
if($info[\\\’id\\\’]==null){
$this->error(\\\’此賬號不存在\\\’);
}
//判斷是否填郵箱
if($info[\\\’email\\\’]!=$email){
$this->error(\\\’郵箱跟您注冊的郵箱不一致\\\’);
}
$key = md5 ( $info [\\\’username\\\’] . \\\’ \\\’ . $info [\\\’password\\\’] ); // MD5不可逆,驗證$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是用來檢驗time是否有修改過
// 調用發(fā)送郵件函數
$username = $info [\\\’username\\\’];
$title="找回密碼";
$content="<h3>親愛的:$username 用戶</h3>
<br><br>請點擊:<a href=\\\’http://$findpwd\\\’>找回密碼</a>
<br><br><h4>請及時修改密碼</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; // 設置采用gb2312中文編碼
$mail->isSMTP (); // 設置采用SMTP方式發(fā)送郵件
$mail->Host = $sys[\\\’mail_host\\\’]; // 設置郵件服務器的地址
$mail->SMTPSecure = \\\’ssl\\\’;
$mail->CharSet = \\\’UTF-8\\\’;
$mail->Port = $sys[\\\’smtp\\\’]; // 設置郵件服務器的端口,默認為25
$mail->From =$sys[\\\’mail_from\\\’]; // 設置發(fā)件人的郵箱地址
$mail->FromName =$sys[\\\’mail_fromname\\\’]; // 設置發(fā)件人的姓名
$mail->SMTPAuth = true; // 設置SMTP是否需要密碼驗證,true表示需要
$mail->Username = $sys[\\\’mail_name\\\’]; // 設置發(fā)送郵件的郵箱
$mail->Password = $sys[\\\’mail_password\\\’]; // 設置郵箱的密碼
$mail->Subject = $title; // 設置郵件的標題
$mail->AltBody = "text/html"; // optional, comment out and test
$mail->Body = $content; // 設置郵件內容
$mail->IsHTML ( true ); // 設置內容是否為html類型
$mail->WordWrap = 50; // 設置每行的字符數
// $mail->AddReplyTo ( "地址", "名字" ); // 設置回復的收件人的地址
$mail->AddAddress ( $to, "" ); // 設置收件的地址
if ($attachment != \\\’\\\’) {
$mail->AddAttachment ( $attachment, $attachment );
}
if ($mail->Send ()) {
//$status1 = "$to" . \\\’ 已投送成功<br />\\\’;
$status = 1;
} else {
//$status2 = "$to" . \\\’ 發(fā)送郵件失敗<br />\\\’;
$status = 0;
}
return $status;
}
更多關于云服務器,域名注冊,虛擬主機的問題,請訪問西部數碼官網:www.bingfeng168.cn