示例#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();
 }
示例#2
0
    protected function sendTestEmail(array $values)
    {
        $projectName = Curry_Core::$config->curry->name;
        $body = <<<HTML
<p>If you can read this email message, then you have correctly configured your email settings.</p>
<p>This is an automated email. Please do not reply.</p>
<pre style="font-size:11pt">
{$values['message']}
</pre>
<br/>
<p>{$projectName}</p>
HTML;
        try {
            $mail = new Curry_Mail();
            $mail->addTo($values['toEmail'], $values['toEmail'])->setFrom(Curry_Core::$config->curry->adminEmail, $projectName)->setSubject('Test email from ' . Curry_Core::$config->curry->name)->setBodyHtml($body)->setBodyText(strip_tags($body))->send();
            if (Curry_Core::$config->curry->divertOutMailToAdmin) {
                $ret = 'Outgoing email was diverted to adminEmail at ' . Curry_Core::$config->curry->adminEmail;
            } else {
                $ret = 'An email has been sent to your email address at ' . $values['toEmail'];
            }
        } catch (Exception $e) {
            $ret = 'An exception has been thrown: ' . $e->getMessage();
        }
        return $ret;
    }
示例#3
0
 /**
  * Send error notification email.
  *
  * @param Exception $e
  */
 public static function sendErrorNotification(Exception $e)
 {
     try {
         // Create form to recreate error
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $hidden = Curry_Html::createHiddenFields($method == 'POST' ? $_POST : $_GET);
         $action = url(Curry_URL::getRequestUri())->getAbsolute();
         $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>';
         // Create mail
         $mail = new Curry_Mail();
         $mail->addTo(Curry_Core::$config->curry->adminEmail);
         $mail->setSubject('Error on ' . Curry_Core::$config->curry->name);
         $mail->setBodyHtml('<html><body>' . '<h1>' . get_class($e) . '</h1>' . '<h2>' . htmlspecialchars($e->getMessage()) . '</h2>' . '<p><strong>Method:</strong> ' . $method . '<br/>' . '<strong>URL:</strong> ' . $action . '<br/>' . '<strong>File:</strong> ' . htmlspecialchars($e->getFile()) . '(' . $e->getLine() . ')</p>' . '<h2>Recreate</h2>' . $form . '<h2>Trace</h2>' . '<pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>' . '<h2>Variables</h2>' . '<h3>$_GET</h3>' . '<pre>' . htmlspecialchars(print_r($_GET, true)) . '</pre>' . '<h3>$_POST</h3>' . '<pre>' . htmlspecialchars(print_r($_POST, true)) . '</pre>' . '<h3>$_SERVER</h3>' . '<pre>' . htmlspecialchars(print_r($_SERVER, true)) . '</pre>' . '</body></html>');
         $mail->send();
         trace_notice('Sent error notification');
     } catch (Exception $e) {
         trace_warning('Failed to send error notification');
     }
 }
示例#4
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;
 }