Example #1
0
 /**
  * Method sendErrorByMail
  * @access static
  * @param mixed $debug_msg 
  * @param string $attachment_file 
  * @param string $error_log_file [default value: error_send_by_mail.log]
  * @param mixed $cache_time [default value: CacheFile::CACHE_TIME_2MIN]
  * @since 1.0.100
  */
 public static function sendErrorByMail($debug_msg, $attachment_file = "", $error_log_file = "error_send_by_mail.log", $cache_time = CacheFile::CACHE_TIME_2MIN)
 {
     if (defined('SEND_ERROR_BY_MAIL') && SEND_ERROR_BY_MAIL == true && !isLocalDebug()) {
         $caching_file = new CacheFile(dirname(__FILE__) . "/../cache/" . $error_log_file, $cache_time);
         if ($caching_file->readCache() == false) {
             $debug_mail = $debug_msg;
             $page_object = Page::getInstance($_GET['p']);
             $debug_mail .= "<br/><b>General information:</b><br/>";
             $debug_mail .= "URL : " . $page_object->getCurrentUrl() . "<br/>";
             $debug_mail .= "Referer : " . $page_object->getRefererURL() . "<br/>";
             $debug_mail .= "IP : <a href='http://www.infosniper.net/index.php?ip_address=" . $page_object->getRemoteIP() . "' target='_blank'>" . $page_object->getRemoteIP() . "</a><br/>";
             $debug_mail .= "Browser : ";
             if (!isset($_SESSION['browser_info']) || $page_object->getBrowserName() == "Default Browser" || $page_object->getBrowserName() == "") {
                 $debug_mail .= $page_object->getBrowserUserAgent();
             } else {
                 $debug_mail .= $page_object->getBrowserName() . " (version: " . $page_object->getBrowserVersion() . ")";
             }
             $debug_mail .= "<br/>";
             if (isset($_SESSION['browser_info'])) {
                 $debug_mail .= "Crawler : " . ($page_object->isCrawlerBot() ? "true" : "false") . "<br/>";
             }
             $caching_file->writeCache($debug_mail);
             try {
                 $mail = new SmtpMail(SEND_ERROR_BY_MAIL_TO, __(SEND_ERROR_BY_MAIL_TO), "ERROR on " . __(SITE_NAME) . " !!!", __($debug_mail), SMTP_MAIL, __(SMTP_NAME));
                 $mail->setPriority(SmtpMail::PRIORITY_HIGH);
                 if ($attachment_file != "" && is_file($attachment_file)) {
                     $mail->addAttachment($attachment_file, basename(str_replace(".cache", ".txt", $attachment_file)));
                 }
                 if (($send_result = $mail->send()) != true) {
                     $caching_file->writeCache("Error when sent mail: " . $send_result . "\nMail: " . $debug_mail);
                     //echo $send_result;
                 }
             } catch (Exception $e) {
                 $caching_file->writeCache("\n\nMail sending error:\n" . $e);
             }
             $caching_file->close();
         }
     }
 }