/**
  * 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);
 }
 /**
  * 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();
 }
 /**
  * Deliver a mail message to the server mail transport using PHP's mail function
  * @param zibo\library\mail\Message $message The message to send
  * @param array $variables Array containing variables to replace in the mail body
  * @return null
  * @throws zibo\ZiboException when the message is not accepted for delivery. Check the installation of the mail tools on the server.
  */
 public function send(Message $message, array $variables = array())
 {
     $parser = new MessageParser($message, $variables);
     $subject = $parser->getSubject();
     $body = $parser->getBody();
     $headers = $parser->getHeaders();
     $headersString = $this->implodeHeaders($headers);
     $additionalParameters = null;
     $returnPath = $message->getReturnPath();
     if ($returnPath) {
         $additionalParameters = '-f ' . $returnPath->getEmailAddress();
     }
     $result = mail(null, $subject, $body, $headersString, $additionalParameters);
     $this->logMail($subject, $headersString, $result);
     if (!$result) {
         throw new MailException('The message is not accepted for delivery. Check your mail configuration on the server.');
     }
 }
 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);
 }
Example #6
0
 /**
  * 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;
 }
 /**
  * Parses the body parts of the provided message
  * @param zibo\library\mail\Message $message The message to parse the parts of
  * @param array $variables Array with variables to replace in the body
  * @return null
  */
 private function parseParts(Message $message, array $variables)
 {
     $attachments = $message->getParts();
     $numParts = count($attachments);
     $body = null;
     if (isset($attachments[Message::PART_BODY])) {
         $body = $attachments[Message::PART_BODY];
         unset($attachments[Message::PART_BODY]);
     }
     $alternative = null;
     if (isset($attachments[Message::PART_ALTERNATIVE])) {
         $alternative = $attachments[Message::PART_ALTERNATIVE];
         unset($attachments[Message::PART_ALTERNATIVE]);
     }
     if (!$alternative && $numParts == 1) {
         $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . $body->getMimeType() . '; charset=' . $body->getCharset();
         $this->headers[self::HEADER_CONTENT_TRANSFER_ENCODING] = self::HEADER_CONTENT_TRANSFER_ENCODING . ': ' . $body->getTransferEncoding();
         $this->addPartToBody($body, $variables, true);
         return;
     }
     $salt = $this->generateSalt();
     if ($alternative && $numParts == 2) {
         $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_ALTERNATIVE . '; boundary=' . $salt;
         $this->addPartsToBody($body, $alternative, $variables, $salt);
         return;
     }
     $this->headers[self::HEADER_CONTENT_TYPE] = self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_MIXED . '; boundary=' . $salt;
     if ($alternative) {
         $messageSalt = $this->generateSalt('message');
         $this->body .= '--' . $salt . "\n";
         $this->body .= self::HEADER_CONTENT_TYPE . ': ' . self::MIME_MULTIPART_ALTERNATIVE . '; boundary=' . $messageSalt . "\n\n";
         $this->addPartsToBody($body, $alternative, $variables, $messageSalt);
     } elseif ($body) {
         $this->body .= '--' . $salt . "\n";
         $this->addPartToBody($body, $variables);
     }
     if (isset($attachments) && is_array($attachments)) {
         foreach ($attachments as $name => $attachment) {
             $this->body .= '--' . $salt . "\n";
             $this->addAttachmentToBody($attachment, $name);
         }
     }
     $this->body .= '--' . $salt . '--' . "\n";
 }
 /**
  * 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();
 }