public function getBodyTextRendered() { $text = $this->getBodyText(); //if the content was manually set with $obj->setBodyText(); this content will be used if ($text instanceof \Zend_Mime_Part) { $rawText = $text->getRawContent(); $content = $this->placeholderObject->replacePlaceholders($rawText, $this->getParams(), $this->getDocument(), $this->getEnableLayoutOnPlaceholderRendering()); } else { //creating text version from html email if html2text is installed try { include_once "simple_html_dom.php"; $htmlContent = $this->getBodyHtmlRendered(); $html = str_get_html($htmlContent); if ($html) { $body = $html->find("body", 0); if ($body) { $style = $body->find("style", 0); if ($style) { $style->clear(); } $htmlContent = $body->innertext; } $html->clear(); unset($html); } $content = $this->html2Text($htmlContent); } catch (\Exception $e) { Logger::err($e); $content = ""; } } return $content; }
/** * @param Document\Newsletter $newsletterDocument * @param SendingParamContainer|null $sendingContainer * @param string|null $hostUrl * @return Mail */ public static function prepareMail(Document\Newsletter $newsletterDocument, SendingParamContainer $sendingContainer = null, $hostUrl = null) { $mail = new Mail(); $mail->setIgnoreDebugMode(true); if (\Pimcore\Config::getSystemConfig()->newsletter->usespecific) { $mail->init("newsletter"); } if (!Tool::getHostUrl() && $hostUrl) { $mail->setHostUrl($hostUrl); } $mail->setDocument($newsletterDocument); if ($sendingContainer && $sendingContainer->getParams()) { $mail->setParams($sendingContainer->getParams()); } $contentHTML = $mail->getBodyHtmlRendered(); $contentText = $mail->getBodyTextRendered(); // render the document and rewrite the links (if analytics is enabled) if ($newsletterDocument->getEnableTrackingParameters()) { if ($contentHTML) { include_once "simple_html_dom.php"; $html = str_get_html($contentHTML); if ($html) { $links = $html->find("a"); foreach ($links as $link) { if (preg_match("/^(mailto)/", trim(strtolower($link->href)))) { continue; } $glue = "?"; if (strpos($link->href, "?")) { $glue = "&"; } $link->href = $link->href . $glue . "utm_source=" . $newsletterDocument->getTrackingParameterSource() . "&utm_medium=" . $newsletterDocument->getTrackingParameterMedium() . "&utm_campaign=" . $newsletterDocument->getTrackingParameterName(); } $contentHTML = $html->save(); $html->clear(); unset($html); } $mail->setBodyHtml($contentHTML); } } $mail->setBodyHtml($contentHTML); $mail->setBodyText($contentText); $mail->setSubject($mail->getSubjectRendered()); return $mail; }