我有以下代码:
Yii::$app->mailer->compose('layouts/html', [
'name' => $this->name,
'email' => $this->email,
'subject' => $this->subject,
'message' => $this->body])
->setTo($this->email)
->setFrom([$this->email])
->setSubject($this->subject)
->send();
如何在layout / html.php中访问姓名,电子邮件,主题和消息?
答案 0 :(得分:1)
很简单,您可以使用$
符号访问姓名,电子邮件,主题和邮件。
$name, $email, $subject, $message
答案 1 :(得分:1)
In your example, you need to replace name of template.
Becouse layouts/html does not need to be explicitly specified.
Yii::$app->mailer->compose('mytemplate',
['name' => $this->name,
'email' => $this->email,
'subject' => $this->subject,
'message' => $this->body])
->setTo($this->email)
->setFrom([$this->email])
->setSubject($this->subject)
->send();
Sample content of mail/mytemplate.php :
<?php
echo "$subject<br> $name<br> $email<br> $message";
And take default content for mail/layouts/html.php here