Swiftmailer显示模板内容两次


Swiftmailer display template content twice

我有这样的控制器:

$mail = Yii::$app->mailer->compose(['html'=>'@app/mail/layouts/html',],['content'=>$_POST["msg"]])
   ->setFrom([Yii::$app->params['admin_email']=>Yii::$app->params['admin_name'])
   ->setTo($_POST["to"])
   ->setSubject($_POST["subject"]);
$mail->send();

在我位于@app/mail/layouts/html 的邮件模板中

<?php $this->beginBody() ?>
This is Email Introduction
<?= $content ?>
<?php $this->endBody() ?>

电子邮件发送成功,但当我要检查收件箱"This is Email Introduction"生成两次时。你可以在这里查看我的最新消息。

我的收件箱收到这样的消息:

This is Email Introduction 
This is Email Introduction 
ini pesan Pesan ke dua

我的密码有问题吗?

很抱歉,我找到了答案。这是我在component's部分的配置@app/config/web.php

    'components'=>[
        'mailer' => [
           'class' => 'yii'swiftmailer'Mailer',
           'viewPath' => '@app/mail',
           'useFileTransport' => false,
           'transport' => [
              'class'=>'Swift_SmtpTransport',
              'host'=>'host.domain.tld', //sample
              'username'=>'my@emaul.com', //sample email
              'password'=>'~!@#$%%^&&', // sample password
              'port'=>'465',
              'encryption'=>'ssl',
           ],
       ],
    ],

我忘记了'viewPath' => '@app/mail'部分作为Swiftmailer的主布局,当我们调用send()函数时会发送
所以当我们有这样的代码时:

$mail = Yii::$app->mailer->compose(['html'=>'@app/mail/layouts/html',],['content'=>$_POST["msg"]])
   ->setFrom([Yii::$app->params['admin_email']=>Yii::$app->params['admin_name'])
   ->setTo($_POST["to"])
   ->setSubject($_POST["subject"]);
$mail->send();

部分['html'=>'@app/mail/layouts/html']告诉我们将使用哪个VIEW