如何设置swiftmailer模板的路径
How to set the path of the swiftmailer templates
我试过的是'viewPath' => '@frontend/views/mail'
。它仍然在搜索 layouts/html
因为它被设置为这个文件。如何覆盖它?我试图将 htmlLayout
属性 留空,但它会搜索 .../frontend/views/mail/.php
。如何禁用(如果我可以这样说的话) htmlLayout
属性 ?我的代码看起来像:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'htmlLayout' => '',
'viewPath' => '@frontend/views/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'localhost',
'username' => Yii::$app->params['adminEmail'],
'password' => Yii::$app->params['adminEmailPass'],
'port' => '587',
'encryption' => 'tls',
],
],
像这样发送邮件:
Yii::$app->mailer->compose('contact',[
'title' => 'test'
])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($model->email)
->setSubject(Yii::t('app', 'Successfully sent message')." - ".Yii::$app->name)
->send();
如 documentation 中所述 - 将其设置为 false
。
我试过的是'viewPath' => '@frontend/views/mail'
。它仍然在搜索 layouts/html
因为它被设置为这个文件。如何覆盖它?我试图将 htmlLayout
属性 留空,但它会搜索 .../frontend/views/mail/.php
。如何禁用(如果我可以这样说的话) htmlLayout
属性 ?我的代码看起来像:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'htmlLayout' => '',
'viewPath' => '@frontend/views/mail',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'localhost',
'username' => Yii::$app->params['adminEmail'],
'password' => Yii::$app->params['adminEmailPass'],
'port' => '587',
'encryption' => 'tls',
],
],
像这样发送邮件:
Yii::$app->mailer->compose('contact',[
'title' => 'test'
])
->setFrom(Yii::$app->params['adminEmail'])
->setTo($model->email)
->setSubject(Yii::t('app', 'Successfully sent message')." - ".Yii::$app->name)
->send();
如 documentation 中所述 - 将其设置为 false
。