Пример #1
0
 /**
  * @param        $content
  * @param string $contentType
  * @param null   $charset
  * @param bool   $ignoreTrackingPixel
  * @param bool   $ignoreEmbedImageConversion
  */
 public function setBody($content, $contentType = 'text/html', $charset = null, $ignoreTrackingPixel = false, $ignoreEmbedImageConversion = false)
 {
     if (!$ignoreEmbedImageConversion && $this->factory->getParameter('mailer_convert_embed_images')) {
         $matches = [];
         if (preg_match_all('/<img.+?src=[\\"\'](.+?)[\\"\'].*?>/i', $content, $matches)) {
             $replaces = [];
             foreach ($matches[1] as $match) {
                 if (strpos($match, 'cid:') === false) {
                     $replaces[$match] = $this->message->embed(\Swift_Image::fromPath($match));
                 }
             }
             $content = strtr($content, $replaces);
         }
     }
     if (!$ignoreTrackingPixel && $this->factory->getParameter('mailer_append_tracking_pixel')) {
         // Append tracking pixel
         $trackingImg = '<img height="1" width="1" src="{tracking_pixel}" alt="" />';
         if (strpos($content, '</body>') !== false) {
             $content = str_replace('</body>', $trackingImg . '</body>', $content);
         } else {
             $content .= $trackingImg;
         }
     }
     // Update the identifier for the content
     $this->contentHash = md5($content . $this->plainText);
     $this->body = ['content' => $content, 'contentType' => $contentType, 'charset' => $charset];
 }