Пример #1
0
 public function actionContact()
 {
     $model = new ContactRequest();
     if ($model->load(Yii::$app->request->post())) {
         $model->email = $model->email ? $model->email : Yii::$app->params['adminEmail'];
         $model->name = $model->name ? $model->name : 'Форма заказа';
         $model->duedate = Yii::$app->formatter->asDatetime($_POST['ContactRequest']['duedate'], 'Y-M-d H:i:s');
         if ($_POST['ContactRequest']['sizes']) {
             $model->sizes = join('; ', $_POST['ContactRequest']['sizes']);
             $model->sizes .= '; ' . $_POST['ContactRequest']['sizesmore'];
         }
         if ($model->save()) {
             $model->attachments = UploadedFile::getInstances($model, 'attachments');
             if ($model->upload()) {
             }
             $subject = 'Новый заказ от ' . $model->name . '<' . $model->email . '>';
             $body = 'Поступила новый заказ от ' . $model->name . '<' . $model->email . '>';
             $body .= '' . $model->initiator . "\n";
             $body .= '' . $model->task_type . "\n";
             $body .= '' . $model->description . "\n";
             $body .= '' . $model->slogan . "\n";
             $body .= '' . $model->sizes . "\n";
             $body .= '' . $model->duedate . "\n";
             $body .= '' . $model->proofs . "\n";
             $body .= 'Смотреть по ссылке ' . Url::to(['requests/view', 'id' => $model->id], true);
             $ses = Yii::$app->mailer->compose()->setTo(Yii::$app->params['adminEmail'])->setFrom([$model->email => $model->name])->setSubject($subject)->setTextBody($body)->send();
             if (!$ses) {
                 Yii::$app->session->setFlash('error', 'There was an error sending email.');
             }
             //create attachments
             Yii::$app->session->setFlash('contactFormSubmitted');
             return $this->refresh();
         }
     }
     return $this->render('contact', ['model' => $model]);
 }
Пример #2
0
 /**
  * Finds the ContactRequest model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ContactRequest the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ContactRequest::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }