public function sendUserEmailCheckCode($user, $type = "regist", $other = null) { $emailModel = new \common\models\entities\EmailCheckCodes(); $checkCode = $this->generatorRandomString(); $emailModel->deleteAll("member_id = '{$user->id}'"); $emailModel->attributes = array("member_id" => $user->id, "check_code" => $checkCode, 'email' => $user->email, 'type' => $type, 'other' => $other); if (!$emailModel->save()) { throw new \yii\web\HttpException(400, $this->formatErrorMsg($emailModel->getErrors()), Yii::$app->controller->errorLayout); } if ($type == EmailCheckCodes::TYPE_REGIST) { $subject = Yii::$app->params["mailCheckCodeTitle"]["register"]; $view = "emailcheck"; $url = $this->toBaseUrl(["user/regist-email-confirm", "checkCode" => $checkCode], true); } elseif ($type == EmailCheckCodes::TYPE_FORGET_PASSWORD) { $subject = Yii::$app->params["mailCheckCodeTitle"]["forgetPwd"]; $view = "emailforgetpwd"; $url = $this->toBaseUrl(["user/forget-pwd-confirm", "checkCode" => $checkCode], true); } else { throw new \yii\web\HttpException(400, "認證碼類型有誤", Yii::$app->controller->errorLayout); } return $this->sendMail($user->email, $user->email, $subject, array("user" => $user, "url" => $url, "other" => $other), $view); }