Контроллер
public function actionIndex(){
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('contactFormSubmitted');
return $this->refresh();
} else {
return $this->render('contact', [
'model' => $model,
]);
}
}
Модель
public function contact($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
return true;
} else {
return false;
}
}
Форма
<?php $form = ActiveForm::begin(['id' => 'contact-form', 'options' => ['class' => 'contact ']]); ?>
<?= $form->field($model, 'name')->label(false)->textInput(array('placeholder' => 'Представьтесь')) ?>
<?= $form->field($model, 'email')->label(false)->textInput(array('placeholder' => 'Обратная связь (почта, skype, телефон)'))?>
<?= $form->field($model, 'body')->textArea(['rows' => 6])->label(false)->textarea(array('placeholder' => 'Ваше сообщение'))?>
<div class="form-group">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
Ошибка