/** * @param Swift_Events_SendEvent $evt */ public function beforeSendPerformed(\Swift_Events_SendEvent $evt) { $message = $evt->getMessage(); $converter = new \TijsVerkoyen\CssToInlineStyles\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()); } } }
function inline_css($html) { $style_start = stripos($html, '<style'); $style_start = stripos($html, '>', $style_start) + 1; $style_end = stripos($html, '</style>', $style_start); $css = substr($html, $style_start, $style_end - $style_start); require_once HAET_MAIL_PATH . '/vendor/autoload.php'; $cssToInlineStyles = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles(); $cssToInlineStyles->setHTML($html); $cssToInlineStyles->setCSS($css); return $cssToInlineStyles->convert(); }