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 */])

->setFrom(‘from@domain.com’)

->setTo(‘someemail@server.com’)

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

->send();

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


Yii::$app->mailer->compose()

    ->setFrom('from@domain.com')

    ->setTo('to@domain.com')

    ->setSubject('Message subject')

    ->setTextBody('Plain text content')

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

    ->send();

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

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

Yii::$app->mailer->compose()

-&gt;setFrom('from@domain.com')


-&gt;setTo('to@domain.com')


-&gt;setSubject('Message subject')


-&gt;setHtmlBody(&#036;htmlContent)


-&gt;send();