コード例 #1
0
 public function actionIndex()
 {
     $model = new Contact();
     if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
         Yii::$app->session->setFlash('contactFormSubmitted');
         return $this->refresh();
     } else {
         return $this->render('index', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: Index.php プロジェクト: scorp7mix/try.t4
 public function actionDefault()
 {
     if (!empty($this->app->request->post->message)) {
         try {
             $question = new Contact();
             $question->fill($this->app->request->post->message);
             $question->save();
             $this->redirect('/contact/sent');
         } catch (MultiException $e) {
             $this->data->errors = $e;
         }
     }
     $this->data->merge($this->app->request->post->message);
     if (empty($this->data->email) && !empty($this->app->user)) {
         $this->data->email = $this->app->user->email;
     }
 }
コード例 #3
0
ファイル: Admin.php プロジェクト: scorp7mix/try.t4
 public function actionSend($id, $email, $theme, $answer)
 {
     $message = Contact::findByPK($id);
     $message->fill($this->app->request->post);
     $message->save();
     $mail = new Sender();
     $mail->sendMail($email, $theme, $answer);
     $this->redirect('/admin/contact');
 }
コード例 #4
0
 /**
  * Sends an email to the specified email address using the information collected by this model.
  * @param  string $email the target email address
  * @return boolean whether the model passes validation
  */
 public function contact($email)
 {
     if (Yii::$app->request->isAjax && $this->load(Yii::$app->request->post())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         echo json_encode(ActiveForm::validate($this));
         Yii::$app->end();
     }
     if ($this->validate()) {
         $user_info = Yii::$app->get('user', false);
         $user_id = $user_info && !$user_info->isGuest ? $user_info->id : null;
         $contact = new Contact();
         $contact->user_id = $user_id;
         $contact->user_email = is_null($user_id) ? $this->user_email : $user_info->identity->email;
         $contact->user_name = is_null($user_id) ? $this->user_name : $user_info->identity->username;
         $contact->user_message = $this->user_message;
         $contact->status = self::STATUS_NEW;
         $contact->verifyCode = $this->verifyCode;
         if ($contact->save()) {
             Yii::$app->mailer->compose()->setTo($email)->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])->setTextBody($this->user_message)->send();
         } else {
             /*                var_dump($contact->getErrors());
                               die();*/
             return false;
         }
         return true;
     } else {
         return false;
     }
 }