Answer the question
In order to leave comments, you need to log in
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:
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,
]);
}
}
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;
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question