Ejemplo n.º 1
0
 /**
  * 发送链接到邮箱
  */
 public function SendlinkEmail()
 {
     $template_name = $this->input['template_name'];
     $this->getEmail();
     $link_url = $this->input['link_url'];
     $identifierUserSystem = new identifierUserSystem();
     $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier();
     //多用户系统
     if ($email = trimall($this->input['email'])) {
         $nick_name = '用户';
         $appicon = '';
         $appname = '找回密码';
         if (hg_check_email_format($email)) {
             $condition = " AND platform_id='" . $email . "' AND mb.type='email' AND mb.identifier=" . $identifier . "";
             $leftjoin = " LEFT JOIN " . DB_PREFIX . "member_bind as mb ON m.member_id=mb.member_id ";
             $memberInfo = $this->Members->get_member_info($condition, $field = ' mb.* ', $leftjoin, '', false);
             $nick_name = $memberInfo['nick_name'];
         }
         $this->type = 'resetpassword';
         $this->verify_email();
         $this->_expire_time = $this->settings['email_token_limit']['time_limit'] ? TIMENOW + $this->settings['email_token_limit']['time_limit'] : TIMENOW + 1000;
         $condition = " AND email='" . $email . "' AND status=0";
         $email_token_info = $this->email_token->show($condition, ' ORDER BY id DESC ', 'limit 1');
         if (!$email_token_info) {
             $this->token = $this->makeToken(16);
         } else {
             $this->token = $email_token_info[0]['token'];
             //如果该验证码已经过期就重新生成验证码
             if ($email_token_info[0]['expire_time'] < TIMENOW) {
                 $this->token = $this->makeToken(16);
                 $this->email_token->update($email, array('status' => 1));
             } else {
                 //如果没有过期,过期时间还是原来的
                 $this->_expire_time = $email_token_info[0]['expire_time'];
             }
         }
         $url = $link_url . '&email=' . $email . '&token=' . $this->token;
         //准备发送邮件
         $sub = $this->input['sub'];
         $preg = array();
         $replace = array();
         if (!empty($sub)) {
             foreach ($sub as $k => $v) {
                 array_push($preg, "{$k}");
                 array_push($replace, "{$v}");
             }
         }
         if ($replace) {
             foreach ($replace as $k => $v) {
                 if ($v == '{membername}') {
                     $replace[$k] = $nick_name;
                 }
                 if ($v == '{link_url}') {
                     $replace[$k] = $url;
                 }
             }
         }
         $htmlBody = file_get_contents(ROOT_DIR . 'email_template/' . $template_name . '.html');
         $content = str_replace($preg, $replace, $htmlBody);
         include ROOT_PATH . 'lib/class/email.class.php';
         $emailapi = new email();
         $param = array('email' => $email, 'content' => $content, 'template_name' => $template_name, 'from' => $this->input['from'], 'fromname' => $this->input['fromname']);
         $result = $emailapi->sendCloudMail($param);
         $data = array('email' => $this->email, 'type' => $this->type, 'status' => 0, 'token' => $this->token, 'create_time' => TIMENOW, 'expire_time' => TIMENOW + $this->settings['email_token_limit']['time_limit']);
         $res = $this->email_token->create($data);
         $this->addItem($data);
         $this->output();
     }
 }