Browse Source

Send message fix

master
Egorka 6 years ago
parent
commit
aa30cbd5ef
  1. 2
      backend/config/params.php
  2. 9
      common/modules/forms/controllers/FormController.php
  3. 2
      common/modules/forms/forms/FormForm.php
  4. 2
      common/modules/forms/messages/ru/form.php
  5. 6
      common/modules/forms/views/manage/form/_form/_form-items.php
  6. 2
      frontend/config/params.php

2
backend/config/params.php

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'adminEmail' => 'admin@example.com', //'adminEmail' => 'admin@example.com',
]; ];

9
common/modules/forms/controllers/FormController.php

@ -57,12 +57,17 @@ class FormController extends FrontendController
// save message // save message
$this->message_service->create($form->id, Json::encode($messageItems, JSON_UNESCAPED_UNICODE)); $this->message_service->create($form->id, Json::encode($messageItems, JSON_UNESCAPED_UNICODE));
//prepare e-mail message //prepare e-mail message
$to = isset($form->return) && $form->return ? explode(',',$form->return) : [Yii::$app->params['adminEmail']];
$from = isset($form->from) && $form->from ? explode(',',$form->from) : [Yii::$app->params['adminEmail']];
$reply = isset($form->reply) && $form->reply ? explode(',',$form->reply) : $from;
$sent = $this->mailer->compose( $sent = $this->mailer->compose(
['html' => '@common/modules/forms/mail/form-html', 'text' => '@common/modules/forms/mail/form-text'], ['html' => '@common/modules/forms/mail/form-html', 'text' => '@common/modules/forms/mail/form-text'],
['items' => $messageItems] ['items' => $messageItems]
) )
->setTo($form->from) ->setTo($to)
->setReplyTo(isset($form->reply) ? $form->reply : $form->from) ->setFrom($from)
->setReplyTo($reply)
->setSubject($form->subject) ->setSubject($form->subject)
->send(); ->send();
if (!$sent) { if (!$sent) {

2
common/modules/forms/forms/FormForm.php

@ -48,7 +48,7 @@ class FormForm extends Model
public function rules(): array public function rules(): array
{ {
return [ return [
[['name', 'from', 'data'], 'required'], [['name', 'data'], 'required'],
[['status', 'captcha', 'complete_page_id'], 'integer'], [['status', 'captcha', 'complete_page_id'], 'integer'],
[['name', 'subject'], 'string', 'max' => 255], [['name', 'subject'], 'string', 'max' => 255],
[['from', 'reply', 'return'], 'email'], [['from', 'reply', 'return'], 'email'],

2
common/modules/forms/messages/ru/form.php

@ -7,7 +7,7 @@ return [
'Subject' => 'Тема сообщения', 'Subject' => 'Тема сообщения',
'From E-mail' => 'Адрес отправителя', 'From E-mail' => 'Адрес отправителя',
'Reply E-mail' => 'Адрес для ответов', 'Reply E-mail' => 'Адрес для ответов',
'Return E-mail' => 'Адрес для возврата', 'Return E-mail' => 'Адрес, кому отправлять уведомления',
'Complete Text' => 'Сообщение после отправки', 'Complete Text' => 'Сообщение после отправки',
'Complete Page' => 'Страница после отправки', 'Complete Page' => 'Страница после отправки',
'Status' => 'Статус', 'Status' => 'Статус',

6
common/modules/forms/views/manage/form/_form/_form-items.php

@ -26,13 +26,13 @@ $fetchUrl = Url::to( [ '/forms/manage/form/page-search' ] );
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
<?= $form->field($model, 'from')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'return')->textInput(['maxlength' => true]) ?>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<?= $form->field($model, 'reply')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'from')->textInput(['maxlength' => true]) ?>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<?= $form->field($model, 'return')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'reply')->textInput(['maxlength' => true]) ?>
</div> </div>
</div> </div>

2
frontend/config/params.php

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'adminEmail' => 'admin@example.com', //'adminEmail' => 'admin@example.com',
]; ];

Loading…
Cancel
Save