Example #1
0
 /**
  * Create a mail from a URL, Page or PageRevision.
  *
  * @param string|\Page|\PageRevision|Request $page
  * @param array $variables Additional template variables.
  * @return Mail
  */
 public static function createFromPage($page)
 {
     $app = \Curry\App::getInstance();
     // Make sure we have a request object
     if (is_string($page)) {
         $request = Request::create($page);
     } elseif ($page instanceof \Page) {
         $request = Request::create($page->getUrl());
     } elseif ($page instanceof \PageRevision) {
         $request = Request::create($page->getPage()->getUrl());
     } elseif ($page instanceof Request) {
         $request = $page;
     } else {
         throw new \Exception('Expected parameter $page to be one of string|Page|PageRevision|Request.');
     }
     // Generate page
     $response = $app->handle($request, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST, false);
     // Create email
     $mail = new Mail();
     $mail->setBodyHtml($response->getContent());
     return $mail;
 }
Example #2
0
    protected function sendTestEmail(array $values)
    {
        $projectName = $this->app['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 Mail();
            $mail->addTo($values['toEmail'], $values['toEmail'])->setFrom($this->app['adminEmail'], $projectName)->setSubject('Test email from ' . $this->app['name'])->setBodyHtml($body)->setBodyText(strip_tags($body))->send();
            if ($this->app['divertOutMailToAdmin']) {
                $ret = 'Outgoing email was diverted to adminEmail at ' . $this->app['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;
    }
Example #3
0
 /** {@inheritdoc} */
 protected function sendMail()
 {
     $r = $this->app->request;
     $html = $this->getMailHtml();
     $text = strip_tags($html);
     $mail = new Mail();
     $mail->setBodyText($text);
     $mail->setBodyHtml($html);
     $mail->setSubject($this->subject);
     $mail->setFrom($this->from, $this->sender);
     if ($r->request->get('email')) {
         $mail->setReplyTo($r->request->get('email'));
     }
     foreach (explode(",", $this->to) as $email) {
         $mail->addTo(trim($email));
     }
     $mail->send();
 }
Example #4
0
 /**
  * Send error notification email.
  *
  * @param Exception $e
  */
 public function sendErrorNotification(Exception $e, Inspector $inspector, Run $run)
 {
     try {
         // Create form to recreate error
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $hidden = Html::createHiddenFields($method == 'POST' ? $_POST : $_GET);
         $action = url(URL::getRequestUri())->getAbsolute();
         $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>';
         // Compose mail
         $content = '<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>';
         // Create and send mail
         $mail = new Mail();
         $mail->addTo($this['adminEmail']);
         $mail->setSubject('Error on ' . $this['name']);
         $mail->setBodyHtml($content);
         $mail->send();
         $this->logger->info('Sent error notification');
     } catch (Exception $e) {
         $this->logger->error('Failed to send error notification');
     }
     return Handler::DONE;
 }