/** * Sets message HTML content. * @param string $input message HTML content. * @return static self reference. * * Note: PHPMailer autocreates both html-body and alt-body (and normalizes text for alt-body), so we need not to set * additionally text body to create 'multipart/alternative' content-type. * * We also try to make possible to call [[setHtmlBody()]] from elsewhere, not only from [[compose()]], * for simple cases, when we have no params to pass to the view to build html, just text. * Othervise you do everything via Mailer [[compose()]] function, passing params their. */ public function setHtmlBody($input) { if (array_key_exists('ishtml', $this->mailer->config) && $this->mailer->config['ishtml'] === false) { //prevent sending html messages if it is explicitly denied in application config $this->setTextBody($input); } else { if (preg_match('|<body[^>]*>(.*?)</body>|is', $input) != 1) { //html was not already rendered by view - lets do it if (empty($this->mailer->htmlView)) { $html = $this->mailer->render($this->mailer->htmlLayout, ['content' => $input], false); } else { //The most simple case is supposed here - your html view file should use '$text' variable $html = $this->mailer->render($this->mailer->htmlView, ['text' => $input], $this->mailer->htmlLayout); } } else { $html = $input; } //TODO: check usage and default behavior of '$basedir' argument (used for images) $this->mailer->adapter->msgHTML($html, $basedir = '', true); } return $this; }
public function compose($view = null, array $params = []) { $message = parent::compose($view, $params); $message->setSubject($this->_subject); return $message; }
<?php return ['vendorPath' => dirname(dirname(__DIR__)) . '/vendor', 'aliases' => ['@file_save_dir' => '@common/files/', '@file_view_url' => '/files/'], 'components' => ['cache' => ['class' => 'yii\\caching\\FileCache'], 'assetManager' => ['appendTimestamp' => true], 'authManager' => ['class' => yii\rbac\DbManager::className(), 'cache' => 'cache', 'defaultRoles' => ['super_admin', 'admin', 'user']], 'view' => ['class' => 'common\\components\\MainView'], 'mailer' => ['class' => \zyx\phpmailer\Mailer::className(), 'viewPath' => '@common/mail', 'useFileTransport' => false, 'messageConfig' => ['from' => ['*****@*****.**']]], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['<controller:\\w+>/<id:\\d+>' => '<controller>/view', '<controller:\\w+>/<action:\\w+>/<id:\\d+>' => '<controller>/<action>', '<controller:\\w+>/<action:\\w+>' => '<controller>/<action>']], 'session' => ['class' => 'yii\\web\\DbSession'], 'i18n' => ['translations' => ['*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en-US']]]]];