Hello,
I have a question regarding contact form and collecting the user input and send it to an email. I’m using Yii2. I was working off of the the default contact form but when sending the information I just see the <body> content of the form, but not the other fields like first name, email zip, etc. Can you help with on how-to?
/Model/
public function contact($email)
{
if ($this->validate()) {
Yii::$app->mailer->compose()
->setTo(['shabangu@msoe.edu'])
->setFrom([$this->email => $this->email])
->setSubject($this->subject)
->setTextBody($this->firstName)
->setTextBody($this->lastName)
->setTextBody($this->jenzId)
->setTextBody($this->email)
->setTextBody($this->subject)
->setTextBody($this->body)
->send();
return true;
}
return false;
}
Here’s View
<?= $form->field($model, 'firstName')->textInput(['autofocus' => true]) ?></div>
<div class="span6"><?= $form->field($model, 'lastName')->textInput(['autofocus' => true]) ?></div></div>
<?= $form->field($model, 'jenzId') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'city')->textInput(); ?>
<?= $form->field($model, 'state')->textInput(); ?>
<!--this is type tel so it propmts the number pad on mobile devices.-->
<?= $form->field($model, 'zip')->input('tel'); ?>
<?= $form->field($model, 'country')->textInput(); ?>
<?= $form->field($model, 'subject')->textInput(); ?>
<?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>