/** * @param object $participation * @return void * @throws \Exception */ public function sendEmail($participation) { $email = $participation->getEmail(); $emailDomain = trim(strtolower(preg_replace('/^[^@]+@/', '', $email))); $participation->setEmailDomain($emailDomain); $participation->save(); $confirmationLink = $this->createConfirmationLink($participation->getConfirmationCode()); $parameters = array('confirmationLink' => $confirmationLink, 'participationId' => $participation->getId()); $emailDocumentPath = Plugin::getConfig()->get('emailDocumentPath'); $emailDocument = DocumentModel::getByPath($emailDocumentPath); if (!$emailDocument instanceof EmailDocument) { throw new \Exception("Error: emailDocumentPath [{$emailDocumentPath}] " . "is not a valid email document."); } $mail = new Mail(); $mail->addTo($email); if ($this->getSubject()) { $mail->setSubject($this->getSubject()); } $mail->setDocument($emailDocumentPath); $mail->setParams($parameters); $mail->send(); $note = new Note(); $note->setElement($participation); $note->setDate(time()); $note->setType("confirmation"); $note->setTitle("Email sent"); $note->addData("email", "text", $email); $note->setUser(0); $note->save(); }
/** * @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)); }
/** * @param null $recipients * @param null $subject * @param null $charset * @return Mail * @throws \Zend_Mail_Exception */ public static function getMail($recipients = null, $subject = null, $charset = null) { $mail = new Mail($charset); if ($recipients) { if (is_string($recipients)) { $mail->addTo($recipients); } else { if (is_array($recipients)) { foreach ($recipients as $recipient) { $mail->addTo($recipient); } } } } if ($subject) { $mail->setSubject($subject); } return $mail; }