diff --git a/backend/controllers/SettingsController.php b/backend/controllers/SettingsController.php index 3be3b99..f81bc22 100755 --- a/backend/controllers/SettingsController.php +++ b/backend/controllers/SettingsController.php @@ -1,6 +1,7 @@ findSettings(); + $mail = Mail::findOne(1); + + if ($mail->load(\Yii::$app->request->post())) { + $mail->save(); + } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', \Yii::t('core', 'Settings saved')); @@ -58,6 +64,7 @@ 'settings', [ 'model' => $model, + 'mail' => $mail, ] ); } diff --git a/backend/views/settings/_mail_tab.php b/backend/views/settings/_mail_tab.php new file mode 100644 index 0000000..fbb1287 --- /dev/null +++ b/backend/views/settings/_mail_tab.php @@ -0,0 +1,20 @@ +field($mail, 'host') + ->textInput(); + + echo $form->field($mail, 'user') + ->textInput(); + + echo $form->field($mail, 'pass') + ->textInput(); \ No newline at end of file diff --git a/backend/views/settings/settings.php b/backend/views/settings/settings.php index a3c67d6..09f9591 100755 --- a/backend/views/settings/settings.php +++ b/backend/views/settings/settings.php @@ -2,8 +2,10 @@ /** * @var View $this * @var Settings $model + * @var Mail $mail */ + use common\models\Mail; use common\models\Settings; use yii\bootstrap\ActiveForm; use yii\bootstrap\Html; @@ -26,7 +28,7 @@ [ @@ -73,10 +75,20 @@ ] ), ], + [ + 'label' => \Yii::t('core', 'Email'), + 'content' => $this->render( + '_mail_tab', + [ + 'form' => $form, + 'mail' => $mail, + ] + ), + ], ], ] ); - + echo Html::submitButton( 'Save', [ diff --git a/common/config/.gitignore b/common/config/.gitignore index b2e5776..7f8b552 100755 --- a/common/config/.gitignore +++ b/common/config/.gitignore @@ -2,4 +2,5 @@ main-local.php db* params-local.php test-local.php -settings.php \ No newline at end of file +settings.php +mail.php \ No newline at end of file diff --git a/common/config/mail.php b/common/config/mail.php new file mode 100755 index 0000000..b5ffe15 --- /dev/null +++ b/common/config/mail.php @@ -0,0 +1,10 @@ + [ + 'host' => 'smtp.gmail.com', + 'user' => 'kennen.md@gmail.com', + 'pass' => 'nobeernoparty', + 'id' => 1, + ], +]; \ No newline at end of file diff --git a/common/config/main.php b/common/config/main.php index 90a5ee4..2b684d8 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -1,6 +1,8 @@ dirname(dirname(__DIR__)) . '/vendor', 'modules' => [ @@ -22,11 +24,11 @@ ], 'i18n' => [ 'translations' => [ - 'core' => [ + 'core' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@artbox/core/messages', ], - 'app' => [ + 'app' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@common/messages', ], @@ -51,5 +53,17 @@ 'useFilename' => true, 'absoluteUrl' => false, ], + 'smtpmailer' => [ + 'class' => 'yii\swiftmailer\Mailer', + 'transport' => [ + 'class' => 'Swift_SmtpTransport', + 'host' => $mail[ 1 ][ 'host' ], + 'username' => $mail[ 1 ][ 'user' ], + 'password' => $mail[ 1 ][ 'pass' ], + 'port' => '587', + 'encryption' => 'tls', + ], + 'viewPath' => '@common/mail' + ], ], ]; diff --git a/common/config/settings.php b/common/config/settings.php index 08e6a39..dd16ed8 100755 --- a/common/config/settings.php +++ b/common/config/settings.php @@ -2,32 +2,32 @@ return [ 1 => [ - 'phone' => '+38 (044) 593-73-76', - 'phone2' => '+38 (098) 468-07-64', - 'skype' => 'artwebstudio', - 'email' => 'artweb.ua@gmail.com', - 'house' => '1-М', - 'street' => 'пр. М. Бажана', - 'office' => '25', - 'city' => 'Киев', - 'country' => 'Украина', - 'lat' => '50.403696', - 'lon' => '30.641481', + 'phone' => '+38 (044) 593-73-76', + 'phone2' => '+38 (098) 468-07-64', + 'skype' => 'artwebstudio', + 'email' => 'kennen.md@gmail.com', + 'house' => '1-М', + 'street' => 'пр. М. Бажана', + 'office' => '25', + 'city' => 'Киев', + 'country' => 'Украина', + 'lat' => '50.403696', + 'lon' => '30.641481', 'facebook' => 'https://www.facebook.com/ArtWeb.ua/', - 'vk' => 'https://vk.com/artwebua', - 'ok' => 'https://ok.ru/artwebua', - 'google' => 'https://plus.google.com/+ArtwebUaAgency', - 'twitter' => 'https://twitter.com/ArtWeb_ua', - 'name' => 'Artweb', - 'logo' => '11', - 'about' => 'Строим бизнес в онлайне', + 'vk' => 'https://vk.com/artwebua', + 'ok' => 'https://ok.ru/artwebua', + 'google' => 'https://plus.google.com/+ArtwebUaAgency', + 'twitter' => 'https://twitter.com/ArtWeb_ua', + 'name' => 'Artweb', + 'logo' => null, + 'about' => 'Строим бизнес в онлайне', 'analytics_key' => '119240817', - 'robots' => 'User-agent: Google + 'robots' => 'User-agent: Google Disallow: ', - 'ga_code' => '796967', - 'ya_code' => '08908908', - 'tag_manager' => '', - 'id' => 1, + 'ga_code' => '796967', + 'ya_code' => '08908908', + 'tag_manager' => '', + 'id' => 1, ], ]; \ No newline at end of file diff --git a/common/mail/feedback.php b/common/mail/feedback.php new file mode 100644 index 0000000..3b0eabf --- /dev/null +++ b/common/mail/feedback.php @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + +
name ?>
phone ?>
email ?>
message ?>
diff --git a/common/models/Mail.php b/common/models/Mail.php new file mode 100644 index 0000000..d98ba7d --- /dev/null +++ b/common/models/Mail.php @@ -0,0 +1,38 @@ +response->format = Response::FORMAT_JSON; - if (empty( Yii::$app->request->post() )) { + + /** + * @var Mailer $mailer + */ + $mailer = \Yii::$app->get('smtpmailer'); + $settings = Settings::getInstance(); + + if (empty(Yii::$app->request->post())) { throw new BadRequestHttpException(); } else { $model = new Feedback(); if ($model->load(Yii::$app->request->post()) && $model->save()) { + + $mailer->compose( + 'feedback', + [ + 'model' => $model, + ] + ) + ->setFrom('artbox@domain.com') + ->setTo($settings->email) + ->setSubject(\Yii::t('app', 'Feedback')) + ->send(); + return [ 'success' => true, 'message' => 'Success message', -- libgit2 0.21.4