/** * Action to ask for extra information and to send the error report * @return null */ public function indexAction() { $zibo = Zibo::getInstance(); $session = Session::getInstance(); $recipient = $zibo->getConfigValue(Module::CONFIG_MAIL_RECIPIENT); $subject = $zibo->getConfigValue(Module::CONFIG_MAIL_SUBJECT); $report = $session->get(Module::SESSION_REPORT); if (!$report || !$recipient) { $this->response->setRedirect($this->request->getBaseUrl()); return; } $form = new ReportForm($this->request->getBasePath()); if ($form->isSubmitted()) { $comment = $form->getComment(); if ($comment) { $report .= "\n\nComment:\n" . $comment; } if (!$subject) { list($subject, $null) = explode("\n", $report, 2); } $mail = new Message(); $mail->setTo($recipient); $mail->setSubject($subject); $mail->setMessage($report); $mail->send(); $session->set(Module::SESSION_REPORT); $this->addInformation(self::TRANSLATION_MAIL_SENT); $this->response->setRedirect($this->request->getBaseUrl()); return; } $view = new ReportView($form, $report); $this->response->setView($view); }
public function testConstructWithAHtmlMessage() { $from = 'Domain <*****@*****.**>'; $to = '*****@*****.**'; $subject = 'subject'; $message = "Hello\n\nThis is a <strong>test</strong> message."; $mail = new Message(); $mail->setFrom($from); $mail->setTo($to); $mail->setSubject($subject); $mail->setMessage($message); $mail->setIsHtmlMessage(true); $expectedHeaders = array('From: Domain <*****@*****.**>', 'To: info <*****@*****.**>', 'MIME-Version: 1.0'); $expectedHeaders = implode("\n", $expectedHeaders); $messageParser = new MessageParser($mail); $headers = implode("\n", $messageParser->getHeaders()); $body = $messageParser->getBody(); $this->assertEquals($subject, $messageParser->getSubject()); $this->assertContains($expectedHeaders, $headers); $this->assertContains($message, $body); $this->assertContains(strip_tags($message), $body); $this->assertContains('Content-Type: multipart/alternative; boundary=', $headers); $this->assertContains('Content-Type: text/html; charset=utf-8', $body); $this->assertContains('Content-Type: text/plain; charset=utf-8', $body); }
/** * Action to show and process the contact form * @return null */ public function indexAction() { $recipient = $this->properties->getWidgetProperty(self::PROPERTY_RECIPIENT); if (!$recipient) { $this->addWarning(self::TRANSLATION_WARNING_RECIPIENT); return; } $captchaManager = CaptchaManager::getInstance(); $form = new ContactWidgetForm($this->request->getBasePath()); $captchaManager->addCaptchaToForm($form); if ($form->isSubmitted()) { try { $form->validate(); $captchaManager->validateCaptcha($form); $name = $form->getName(); $email = $form->getEmail(); $message = $form->getMessage(); $subject = $this->properties->getWidgetProperty(self::PROPERTY_SUBJECT); $mail = new Message(); $mail->setFrom($name . ' <' . $email . '>'); $mail->setTo($recipient); $mail->setSubject($subject); $mail->setMessage($message); $mail->send(); $this->addInformation(self::TRANSLATION_MESSAGE_SENT); $this->response->setRedirect($this->request->getBasePath()); return; } catch (ValidationException $e) { } catch (CaptchaException $e) { } } $captchaView = $captchaManager->getCaptchaView($form); $view = new ContactWidgetView($form, $captchaView); $this->response->setView($view); }
/** * Creates the mail message * @return zibo\library\mail\Message */ protected function createMail() { $mail = new Message(); $mail->setSubject($this->subject); $mail->setMessage($this->parseMessage($this->message)); $mail->setIsHtmlMessage(true); $mail->removePart(MailMessage::PART_ALTERNATIVE); return $mail; }
/** * Sends a mail to the provided user * @param zibo\library\security\model\User $user The user * @param string $url The URL to be parsed in the message * @return null */ protected function sendMail(User $user, $url) { $subject = $this->getSubject(); $message = $this->getMessage(); $username = $user->getUserName(); $email = $user->getUserEmail(); $message = str_replace('%username%', $username, $message); $message = str_replace('%email%', $email, $message); if ($url) { $message = str_replace('%url%', $url, $message); } $mail = new Message(); $mail->setTo($email); $mail->setSubject($subject); $mail->setMessage($message); $mail->send(); }
/** * Sends a mail to the provided subscriber to request a unsubscribe * @param joppa\mailinglist\model\data\SubscriberData $subscriber The subscriber who wants to unsubscribe * @return null */ public function requestUnsubscribe(SubscriberData $subscriber) { $translator = I18n::getInstance()->getTranslator(); $zibo = Zibo::getInstance(); $sender = $zibo->getConfigValue(self::CONFIG_SENDER); $website = $zibo->getRequest()->getBaseUrl(); $unsubscribeUrl = $website . $zibo->getConfigValue(self::CONFIG_UNSUBSCRIBE_PATH); $confirmUrl = $unsubscribeUrl . '/' . $subscriber->email . '/' . $subscriber->getUnsubscribeKey(); $parameters = array('email' => $subscriber->email, 'confirmUrl' => $confirmUrl, 'unsubscribeUrl' => $unsubscribeUrl, 'website' => $website); $subject = $translator->translate(self::TRANSLATION_UNSUBSCRIBE_SUBJECT, $parameters); $message = $translator->translate(self::TRANSLATION_UNSUBSCRIBE_MESSAGE, $parameters); $mail = new Message(); if ($sender) { $mail->setFrom($sender); } $mail->setTo($subscriber->email); $mail->setSubject($subject); $mail->setMessage($message); $mail->setIsHtmlMessage(true); $mail->send(); }