/** * Creates a new Customer model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } // $this->layout = false; $model = new Customer(); $model->scenario = 'create'; if (Yii::$app->request->isPost && ($model = Customer::create(Yii::$app->request->post()))) { if (!$model->hasErrors()) { try { Yii::$app->mailer->compose(['html' => 'helloNewCustomer-html', 'text' => 'helloNewCustomer-text'], ['customer' => $model])->setFrom([Yii::$app->params['noreply_email'] => Yii::$app->name])->setTo($model->email)->setSubject(I18n::t('Hello new customer'))->send(); } catch (yii\base\Exception $e) { } if (Yii::$app->user->login($model)) { Yii::$app->session->setFlash('success', I18n::t('Your account created successfully')); return $this->goHome(); } } } return $this->render('create', ['model' => $model]); }