/** * @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; }
public function sendTestEmailAction() { if (!$this->getUser()->isAllowed("emails")) { throw new \Exception("Permission denied, user needs 'emails' permission."); } $mail = new Mail(); $mail->addTo($this->getParam("to")); $mail->setSubject($this->getParam("subject")); $mail->setIgnoreDebugMode(true); if ($this->getParam("type") == "text") { $mail->setBodyText($this->getParam("content")); } else { $mail->setBodyHtml($this->getParam("content")); } $mail->send(); $this->_helper->json(array("success" => true)); }