如何设置swiftmailer模板的路径

时间:2018-11-19 20:49:38

标签: yii2 yii2-advanced-app

我尝试的是'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();

1 个答案:

答案 0 :(得分:1)

documentation中所述-将其设置为false