示例#1
0
 /**
  * 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);
 }
 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);
 }
 /**
  * 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();
 }