php - Yii2: using Swiftmailer Plugin (Openbuildings\Swiftmailer\CssInlinerPlugin) -
my yii2 application sends out emails yii2 swiftmailer extension using given default layout in \app\mail\layouts
named html.php
yii::$app->mailer->compose('@app/mail/templates/mytemplate', [ 'param1' => $param1, 'param2' => $param2 ])->setfrom($senderadress)->setto($reveiveradress)->setsubject('subject')->send();
unfortunately way css within style tags in header not included in html.php
suggested official yii2 guide yiiframework.com/doc-2.0/guide-tutorial-mailing.html (the given example was:
<head> <meta http-equiv="content-type" content="text/html; charset=<?= yii::$app->charset ?>" /> <style type="text/css"> .heading {...} .list {...} .footer {...} </style> <?php $this->head() ?> </head>
so tried include openbuildings swiftmailer css-inliner-plugin installing via composer , including suggested in this tutorial extending web.php
to:
'mailer' => [ 'class' => 'yii\swiftmailer\mailer', 'transport' => [ 'class' => 'swift_smtptransport', 'host' => 'smtp.xyz.com', 'username' => 'username', 'password' => 'password', 'port' => '587', 'encryption' => 'tls', 'plugins' => [ [ 'class' => 'openbuildings\swiftmailer\cssinlinerplugin', ], ], ], ],
mails still sent without included <style>
tags content. has experience including plugins yii2 swiftmailer extension? or there way of using extension there no need use swiftmailer plugins @ all?
a bit late, might finding later...
i used same code including cssinlinerplugin plugin , worked right away. registered css in mail view, this.
$this->registercss(" p, td, th {text-align: left; font-size: 12px; } .classname {color: blue; } ");
...and in mail sent , html tags had same styles inline. plugin seems work fine.
regarding last question. have not found better way handle yii2 using plugin. plugin based on package tijsverkoyen/css-to-inline-styles, used in other frameworks well.
noticed in source code tijsverkoyen\csstoinlinestyles css-classnames stripped style-tag in mail, css-content passed on correct tag. maybe explain part of saw? (this behaviour configurable of course.)
Comments
Post a Comment