コード例 #1
0
 /**
  * Looks up user supplied email address / alias and sends a mail
  *
  * @param $email email address or username
  */
 function sendMail($in)
 {
     $in = trim($in);
     if (is_email($in)) {
         $user_id = UserFinder::byEmail($in);
     } else {
         $user_id = UserFinder::byUsername($in);
     }
     $error = ErrorHandler::getInstance();
     if (!$user_id) {
         $error->add('Invalid email address or username');
         return false;
     }
     $email = UserSetting::getEmail($user_id);
     if (!$email) {
         throw new \Exception('entered email not found');
     }
     $code = Token::generate($user_id, 'activation_code');
     $pattern = array('/@USERNAME@/', '/@IP@/', '/@URL@/', '/@EXPIRETIME@/');
     $user = User::get($user_id);
     $page = XmlDocumentHandler::getInstance();
     $url = $page->getUrl() . 'u/reset_pwd/' . $code;
     $replacement = array($user->getName(), client_ip(), $url, shortTimePeriod($this->expire_time_email));
     $msg = preg_replace($pattern, $replacement, $this->password_msg);
     //d($msg);
     $mail = SendMail::getInstance();
     $mail->addRecipient($email);
     $mail->setSubject('Forgot password');
     $mail->send($msg);
     return true;
 }