Esempio n. 1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     $this->inliner = new CssToInlineStyles();
     $this->inliner->setCleanup(true);
     $this->inliner->setUseInlineStylesBlock(true);
     $this->inliner->setStripOriginalStyleTags(true);
 }
Esempio n. 2
0
 /**
  * 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();
 }
Esempio n. 3
0
 /**
  * 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']);
 }
 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()));
     }
 }
Esempio n. 5
0
 /**
  * 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;
 }
Esempio n. 6
0
 /**
  * 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());
         }
     }
 }
Esempio n. 8
0
 /**
  * {@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)]]);
 }
 /**
  * If set to true, this function will activate the removal of the
  * IDs and classes inside the HTML document during conversion.
  *
  * This option is false by default.
  *
  *
  * @param  bool[optional] $on Should we enable cleanup?
  */
 public function setCleanup($on = true)
 {
     $this->cleanup = (bool) $on;
     $this->cssToInlineStyles->setCleanup($this->cleanup);
 }