/** * @param Model\Tool\Newsletter\Config $newsletter * @param Object\Concrete $object */ public static function sendMail($newsletter, $object, $emailAddress = null, $hostUrl = null) { $params = ["gender" => $object->getGender(), 'firstname' => $object->getFirstname(), 'lastname' => $object->getLastname(), "email" => $object->getEmail(), 'token' => $object->getProperty("token"), "object" => $object]; $mail = new Mail(); $mail->setIgnoreDebugMode(true); if (\Pimcore\Config::getSystemConfig()->newsletter->usespecific) { $mail->init("newsletter"); } if (!Tool::getHostUrl() && $hostUrl) { $mail->setHostUrl($hostUrl); } if ($emailAddress) { $mail->addTo($emailAddress); } else { $mail->addTo($object->getEmail()); } $mail->setDocument(Document::getById($newsletter->getDocument())); $mail->setParams($params); // render the document and rewrite the links (if analytics is enabled) if ($newsletter->getGoogleAnalytics()) { if ($content = $mail->getBodyHtmlRendered()) { include_once "simple_html_dom.php"; $html = str_get_html($content); 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=Newsletter&utm_medium=Email&utm_campaign=" . $newsletter->getName(); } $content = $html->save(); $html->clear(); unset($html); } $mail->setBodyHtml($content); } } $mail->send(); }