I could really use a hand here because I’m going a little crazy. I am able to do the following with no problem:
Yii::$app->mailer->compose('myHtmlTemplate')
->setTo($this->toAddress)
->setFrom([$this->fromDefaultAddress => $this->fromDefaultName])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
This works fine, email sends perfectly with my view and layout. However, I cannot get it to work when I add parameters like this:
Yii::$app->mailer->compose('myHtmlTemplate', ['myTestVar' => 'Hello, World'])
->setTo($this->toAddress)
->setFrom([$this->fromDefaultAddress => $this->fromDefaultName])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
and in my myHtmlTemplate view I add:
<?= $myTestVar ?>
The email does not send after I add this variable to the view. I continue to get a “Undefined variable: myTestVar” error. Can anybody suggest what I may doing wrong? The documentation never shows how I should be attempting to code the myTestVar variable in a template, but StackOverflow and other sites seem to suggest exactly what I’m doing.
Again, this works until I attempt to pass a variable to my HTML template view. Any thoughts? Thanks in advance!