/** * Constructor. */ public function __construct() { $this->inliner = new CssToInlineStyles(); $this->inliner->setCleanup(true); $this->inliner->setUseInlineStylesBlock(true); $this->inliner->setStripOriginalStyleTags(true); }
/** * @param CssToInlineStyles $converter */ public function __construct(CssToInlineStyles $converter = null) { if ($converter) { $this->converter = $converter; } else { $this->converter = new CssToInlineStyles(); $this->converter->setUseInlineStylesBlock(true); } }
/** * Transform the found css to inline styles */ public function transformCssToInlineStyles($html) { // Clean-up html $this->cssInliner->setCleanup(true); // Set html $this->cssInliner->setHtml($html); // Use inline style blocks $this->cssInliner->setUseInlineStylesBlock(true); // Loop through all stylesheets foreach ($this->links as $link) { $css = file_get_contents($link); $this->cssInliner->setCSS($css); } return $this->cssInliner->convert(); }
/** * Configure the internal inliner. */ protected function configure() { $this->internalInliner->setCleanup($this->options['cleanup']); $this->internalInliner->setUseInlineStylesBlock($this->options['use_inline_styles_block']); $this->internalInliner->setStripOriginalStyleTags($this->options['strip_original_tags']); $this->internalInliner->setExcludeMediaQueries($this->options['exclude_media_queries']); }
/** * Bootstrap the application services. */ public function boot() { $converter = new CssToInlineStyles(); $converter->setUseInlineStylesBlock(true); $converter->setStripOriginalStyleTags(true); $this->app[Mailer::class]->getSwiftMailer()->registerPlugin(new CssInlinerPlugin($converter)); }
public function send($view, array $data, $callback) { $message = new Message(new Swift_Message()); if ($callback instanceof Closure) { // callback must assign $to and $subject, deal with it call_user_func($callback, $message); } else { throw new InvalidArgumentException('Callback is not valid.'); } $m = $message->getSwiftMessage(); $filteredTo = array_filter(array_keys($message->getTo()), function ($email) { $skip = DB::table('ses_feedback')->where('email', $email)->first(); if ($skip) { Log::info("skipping email:{$email}"); } return !$skip; }); if ($filteredTo) { $converter = new CssToInlineStyles(); $converter->setEncoding($message->getCharset()); $converter->setStripOriginalStyleTags(); $converter->setUseInlineStylesBlock(); $converter->setExcludeMediaQueries(false); $converter->setCleanup(); $converter->setHTML(View::make($view, $data)->render()); $body = $converter->convert(); $config = Config::get('services.amazon'); SesClient::factory($config)->sendEmail(array('Source' => $config['from'], 'Destination' => array('ToAddresses' => $filteredTo), 'Message' => array('Subject' => array('Data' => $m->getSubject(), 'Charset' => 'UTF-8'), 'Body' => array('Text' => array('Data' => strip_tags(str_replace("<br/>", "\n", $body)), 'Charset' => 'UTF-8'), 'Html' => array('Data' => $body, 'Charset' => 'UTF-8'))), 'ReplyToAddresses' => array())); } }
/** * Inline all css styles * @param string $html * @return string */ private function cssToInline($html) { $inlineConverter = new CssToInlineStyles($html); $inlineConverter->setUseInlineStylesBlock(true); $inlineConverter->setStripOriginalStyleTags(true); return $inlineConverter->convert(); }
/** * Convert to inlined CSS * * @return string * @throws \TijsVerkoyen\CssToInlineStyles\Exception */ public function convert() { $converter = new CssToInlineStyles(); $converter->setUseInlineStylesBlock(); $converter->setCleanup(); $converter->setStripOriginalStyleTags(); $converter->setHTML($this->view); $content = $converter->convert(); return $content; }
/** * Attach event listeners on boot. * * @return void */ public function boot() { // When preparing html to be sent Event::listen('mailer.prepareSend', function ($self, $view, $message) { // Get the Swift mail message $swift = $message->getSwiftMessage(); // Convert to inline css $cssToInlineStyles = new CssToInlineStyles($swift->getBody()); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setCleanup(true); $cssToInlineStyles->setStripOriginalStyleTags(true); // Set the body of mail $swift->setBody($cssToInlineStyles->convert()); }, 1); }
/** * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(\Swift_Events_SendEvent $evt) { $message = $evt->getMessage(); $converter = new CssToInlineStyles(); $converter->setEncoding($message->getCharset()); $converter->setUseInlineStylesBlock(); $converter->setCleanup(); if ($message->getContentType() === 'text/html' || $message->getContentType() === 'multipart/alternative' && $message->getBody() || $message->getContentType() === 'multipart/mixed' && $message->getBody()) { $converter->setHTML($message->getBody()); $message->setBody($converter->convert()); } foreach ($message->getChildren() as $part) { if (strpos($part->getContentType(), 'text/html') === 0) { $converter->setHTML($part->getBody()); $part->setBody($converter->convert()); } } }
/** * {@inheritdoc} */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $client = $this->getHttpClient(); // Inline CSS here $converter = new CssToInlineStyles(); $converter->setEncoding($message->getCharset()); $converter->setUseInlineStylesBlock(); $converter->setCleanup(); if ($message->getContentType() === 'text/html' || $message->getContentType() === 'multipart/alternative' && $message->getBody()) { $converter->setHTML($message->getBody()); $message->setBody($converter->convert()); } foreach ($message->getChildren() as $part) { if (strpos($part->getContentType(), 'text/html') === 0) { $converter->setHTML($part->getBody()); $part->setBody($converter->convert()); } } // Call the API $client->post($this->url, ['auth' => ['api', $this->key], 'body' => ['to' => $this->getTo($message), 'message' => new PostFile('message', (string) $message)]]); }
public function convert($html, $css = null) { $cssToInlineStyles = new CssToInlineStyles($html, $css); $cssToInlineStyles->setUseInlineStylesBlock($css === null); return $cssToInlineStyles->convert(false); }
/** * Inline all css into style attributes * * @param string $html * @param string $css * @return string * @throws \TijsVerkoyen\CssToInlineStyles\Exception * @see https://github.com/tijsverkoyen/CssToInlineStyles */ protected function inlineStyles($html, $css) { // fix known issue in library with character encoding. $charsetMeta = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; $html = $charsetMeta . $html; // add default css to every template $css .= file_get_contents(__DIR__ . '/styles/common.css'); $inliner = new CssToInlineStyles($html, $css); $inliner->setUseInlineStylesBlock(); $html = $inliner->convert(); return $html; }
/** * Converts all css to inline styles * * @param string $html * @return string */ private function cssToInlineStyles($html) { $charset = Model::getContainer()->getParameter('kernel.charset'); $cssToInlineStyles = new CssToInlineStyles(); $cssToInlineStyles->setHTML($html); $cssToInlineStyles->setUseInlineStylesBlock(true); $cssToInlineStyles->setEncoding($charset); return (string) $cssToInlineStyles->convert(); }
/** * Set use of inline styles block * If this is enabled the class will use the style-block in the HTML. * * This option is false by default. * * @param bool[optional] $on Should we process inline styles? */ public function setUseInlineStylesBlock($on = true) { $this->useInlineStylesBlock = (bool) $on; $this->cssToInlineStyles->setUseInlineStylesBlock($this->useInlineStylesBlock); }
/** * Converts all css to inline styles * * @param string $html * * @return string */ private function cssToInlineStyles($html) { $cssToInlineStyles = new CssToInlineStyles(); $cssToInlineStyles->setHTML($html); $cssToInlineStyles->setUseInlineStylesBlock(true); return (string) $cssToInlineStyles->convert(); }