Ejemplo n.º 1
0
 /**
  * @param $recipients array
  * @param $subject string
  * @param $body string
  */
 public static function sendEmail($recipients, $subject, $body)
 {
     \ipinga\email::$host = \ipinga\options::get('email_host');
     \ipinga\email::$port = (int) \ipinga\options::get('email_port');
     \ipinga\log::debug('option email_auth = [' . \ipinga\options::get('email_auth') . ']');
     if (strtolower(\ipinga\options::get('email_auth')) == 'yes') {
         \ipinga\email::$auth = true;
         \ipinga\email::$username = \ipinga\options::get('email_username');
         \ipinga\email::$password = \ipinga\options::get('email_password');
     } else {
         \ipinga\email::$auth = false;
         \ipinga\email::$username = '';
         \ipinga\email::$password = '';
     }
     \ipinga\email::$localhost = \ipinga\options::get('email_localhost');
     \ipinga\email::$timeout = (int) \ipinga\options::get('email_timeout');
     \ipinga\email::$debug = false;
     \ipinga\email::$from = \ipinga\options::get('email_from');
     \ipinga\email::$recipients = $recipients;
     // \ipinga\email::$bcc[] = '*****@*****.**';
     \ipinga\email::$subject = $subject;
     \ipinga\email::$textBody = $body;
     // \ipinga\email::$htmlBody = '';
     $success = \ipinga\email::send();
     if ($success === true) {
         \ipinga\log::info('(services.sendEmail) success!');
     } else {
         \ipinga\log::warning('(services.sendEmail) failed to send email to ' . var_export($recipients, true));
     }
 }
Ejemplo n.º 2
0
 public function run()
 {
     $rt = isset($_GET['rt']) ? $_GET['rt'] : '';
     // I use output buffering to make sure any cookies that are set in the code get handled properly.
     // ie: sent in the header instead of inline with the html, etc as they are generated.
     ob_start();
     $routeHandled = false;
     foreach ($this->routes as $route) {
         /* @var $route \ipinga\route */
         if ($route->handled($rt) == true) {
             $routeHandled = true;
             break;
         }
     }
     if ($routeHandled === false) {
         if (count($this->defaultRoute) == 2) {
             \ipinga\log::debug('Firing default route');
             //if (isset($_GET['rt'])==false) {
             \ipinga\route::launchController($this->defaultRoute[0], $this->defaultRoute[1], array());
             //} else {
             //    header('location: /');
             //}
         } else {
             echo 'No route found!' . PHP_EOL;
         }
     }
 }
Ejemplo n.º 3
0
 public static function send()
 {
     // setup the headers.  Stays the same for bcc as well as non-bcc recipients
     self::$now = date('D, d M Y H:i:s O (T)');
     self::$headers['From'] = self::$from;
     self::$headers['Date'] = self::$now;
     self::$headers['To'] = '';
     foreach (self::$recipients as $r) {
         if (self::$headers['To'] != '') {
             self::$headers['To'] .= ' , ';
         }
         self::$headers['To'] .= $r;
     }
     self::$headers['Subject'] = self::$subject;
     self::$mimeParams = array();
     /*
         eol             - Type of line end. Default is ""\r\n"".
         delay_file_io   - Specifies if attachment files should be read immediately when adding them into message
                           object or when building the message. Useful for big messages handling using saveMessage
                           functions. Default is "false".
         head_encoding   - Type of encoding to use for the headers of the email. Default is "quoted-printable".
         text_encoding   - Type of encoding to use for the plain text part of the email. Default is "quoted-printable".
         html_encoding   - Type of encoding for the HTML part of the email. Default is "quoted-printable".
         head_charset    - The character set to use for the headers. Default is "iso-8859-1".
         text_charset    - The character set to use for the plain text part of the email. Default is "iso-8859-1".
         html_charset    - The character set to use for the HTML part of the email. Default is "iso-8859-1".
     */
     self::$mimeParams['eol'] = "\n";
     $mime = new \Mail_mime(self::$mimeParams);
     // never try to call these lines in reverse order!!  Bad things happen!!
     $mime->setTXTBody(self::$textBody);
     // must call first
     $mime->setHTMLBody(self::$htmlBody);
     // must call second
     // must add attachments AFTER setting the bodies (above)
     foreach (self::$attachments as $filename => $type) {
         $mime->addAttachment($filename, $type);
     }
     // this could be used to override the params used above when creating $mime
     //$getparams = array();
     //$getparams["text_encoding"] = '8bit';
     //$b = $mime->get($getparams);
     $mimeBody = $mime->get();
     // Tell mime to build the message and get the results
     $mimeHdr = $mime->headers(self::$headers);
     $smtp = \Mail::factory('smtp', self::smtpServerDetailsAsArray());
     // send any BCC emails, but doesn't die if failure sending
     $result = true;
     if (count(self::$bcc) > 0) {
         \ipinga\log::debug('(email) about to send BCC email');
         $result = self::trySmtp($smtp, self::$bcc, $mimeHdr, $mimeBody);
         if ($result === true) {
             \ipinga\log::debug('(email) BCC sent successfully');
         } else {
             \ipinga\log::error('(email) BCC failed');
         }
     }
     // now send to everyone else
     if ($result == true) {
         \ipinga\log::debug('(email) about to send email');
         $result = self::trySmtp($smtp, self::$recipients, $mimeHdr, $mimeBody);
         if ($result === true) {
             \ipinga\log::debug('(email) sent successfully');
         } else {
             \ipinga\log::error('(email) failed');
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 private function processMiddleWare()
 {
     $middlewareList = explode('|', $this->middleware);
     $ipinga = \ipinga\ipinga::getInstance();
     $result = true;
     foreach ($middlewareList as $mw) {
         if (empty($mw) == false) {
             $middlewareFile = $ipinga->config('path.middleware') . '/' . $mw . '.middleware.php';
             // include the middleware
             require_once $middlewareFile;
             // a new controller class instance
             $class = $mw . 'Middleware';
             $middleware = new $class();
             $result = call_user_func_array(array($middleware, 'call'), array($ipinga));
             if ($result === false) {
                 break;
             }
         }
     }
     \ipinga\log::debug('middleware ' . $this->middleware . ' is returning ' . $result);
     return $result;
 }