M
M
MaikMain2018-08-12 17:33:56
Yii
MaikMain, 2018-08-12 17:33:56

How to pass the received values ​​to the message. Yii2?

Good afternoon. I have a feedback form from a Yii2 advanced box.
The letter is sent successfully. But there is a problem, I don’t know how to transfer this data to the message file itself, which is located (common/mail/contact.php)
Controller:

spoiler
public function actionContact()
    {
        /* Создаем экземпляр класса */
        $model = new ContactForm();
        /* получаем данные из формы и запускаем функцию отправки contact, если все хорошо, выводим сообщение об удачной отправке сообщения на почту */
        if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['emailto'])) {
            Yii::$app->session->setFlash('contactFormSubmitted');
            return $this->refresh();
            /* иначе выводим форму обратной связи */
        } else {
            return $this->render('contact', [
                'model' => $model,
            ]);
        }
    }

Model:
spoiler
public function contact($emailto)
    {
        /* Проверяем форму на валидацию */
        if ($this->validate()) {
            Yii::$app->mailer->compose('contact')
                ->setFrom([Yii::$app->params['adminEmail'] => $this->name]) /* от кого */
                ->setTo($emailto) /* куда */
                ->setSubject($this->subject) /* имя отправителя */
                ->setTextBody($this->body) /* текст сообщения */
                ->send(); /* функция отправки письма */
            return true;
        } else {
            return false;
        }
    }

Tell me how can I transfer the data received from the user (Name, email, phone, subject, text) to this file common/mail/contact.php
And just list this data in it?
Thank you very much in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-08-12
@webinar

https://www.yiiframework.com/extension/yiisoft/yii...

Yii::$app->mailer
              ->compose('contact', [
                   'someVarName' => $someData,
                   'someModel' => $this,
                   'currentUser' => Yii::$app->user->identity,
                   'mySuperVar' => 'да это она, дайте две'
              ])
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question