Esempio n. 1
0
 /** {@inheritdoc} */
 protected function sendMail()
 {
     $html = $this->getMailHtml();
     $text = strip_tags($html);
     $mail = new Curry_Mail();
     $mail->setBodyText($text);
     $mail->setBodyHtml($html);
     $mail->setSubject($this->subject);
     $mail->setFrom($this->from, $this->sender);
     if (isset($this->getRequest()->post['email'])) {
         $mail->setReplyTo($this->getRequest()->post['email']);
     }
     foreach (explode(",", $this->to) as $email) {
         $mail->addTo(trim($email));
     }
     $mail->send();
 }
Esempio n. 2
0
 /**
  * Create a mail from a URL, Page or PageRevision.
  *
  * @param string|Page|PageRevision $page
  * @param Curry_Request $request
  * @param array $variables Additional template variables.
  * @return Curry_Mail
  */
 public static function createFromPage($page, $request = null, array $variables = array())
 {
     $app = Curry_Application::getInstance();
     // If a URL is provided, attempt to find page using route
     if (is_string($page)) {
         $r = new Curry_Request('GET', (string) url($page));
         $page = $app->findPage($r);
         if (!$request) {
             $request = $r;
         }
     }
     // Find PageRevision
     if ($page instanceof PageRevision) {
         $pageRevision = $page;
     } elseif ($page instanceof Page) {
         $pageRevision = $page->getPageRevision();
         if (!$pageRevision) {
             throw new Exception('Page has no active revision.');
         }
     } else {
         throw new Exception('$page is of invalid type, expected Page or PageRevision.');
     }
     // Create Curry_Request object if not provided
     $oldVal = Curry_URL::setPreventRedirect(true);
     if (!$request) {
         $url = (string) url($pageRevision->getPage()->getUrl());
         $request = new Curry_Request('GET', $url);
     }
     // Generate page
     $pageGenerator = $app->createPageGenerator($pageRevision, $request);
     $content = $pageGenerator->render($variables);
     // Create email
     $mail = new Curry_Mail();
     $mail->setBodyHtml($content);
     $mail->setBodyText(strip_tags($content));
     // restore redirect status
     Curry_URL::setPreventRedirect($oldVal);
     return $mail;
 }