Yii2 swiftmailer sending twice

In Yii2 swiftmailer, Cant understand why this method in docs example has two views, one for html and another one for text message. In one moment why this sending use two views, which one will work or both of them will sended twice.

Yii::$app->mail->compose([‘html’ => ‘@app/mail-templates/html-email-01’, ‘text’ => ‘@app/mail-templates/text-email-01’], [/*Some params for the view */])



->setSubject(‘Advanced email from Yii2-SwiftMailer’)


in my case it works twice, and both of them come into me email on html.


actually if you want to send text message only then use text , or you want some HTML means some GUI in your email then you need to use HTML . Both at a time will work . So try it again and check it . use this code and check




    ->setSubject('Message subject')

    ->setTextBody('Plain text content')

    ->setHtmlBody('<b>HTML content</b>')


I had the same problem and I solved with a renderParial. Something like this:

$htmlContent = $this->renderPartial(’_email’, []);




-&gt;setSubject('Message subject')