protected function sendSoftLimitAlert()
 {
     $mailers = AJXP_PluginsService::getInstance()->getPluginsByType("mailer");
     if (count($mailers)) {
         $this->mailer = array_shift($mailers);
         $percent = $this->getFilteredOption("SOFT_QUOTA");
         $quota = $this->getFilteredOption("DEFAULT_QUOTA");
         $this->mailer->sendMail(array(AuthService::getLoggedUser()->getId()), "You are close to exceed your quota!", "You are currently using more than {$percent}% of your authorized quota of {$quota}!");
     }
 }
 protected function sendMailImpl($recipients, $subject, $body, $from = null, $images = array(), $useHtml = true)
 {
     require_once "lib/class.phpmailer-lite.php";
     $realRecipients = $this->resolveAdresses($recipients);
     // NOW IF THERE ARE RECIPIENTS FOR ANY REASON, GO
     $mail = new PHPMailerLite(true);
     $mail->Mailer = $this->getFilteredOption("MAILER");
     $mail->Sendmail = $this->getFilteredOption("SENDMAIL_PATH");
     $from = $this->resolveFrom($from);
     if (!is_array($from) || empty($from["adress"])) {
         throw new Exception("Cannot send email without a FROM address. Please check your core.mailer configuration.");
     }
     if (!empty($from)) {
         if ($from["adress"] != $from["name"]) {
             $mail->SetFrom($from["adress"], $from["name"]);
         } else {
             $mail->setFrom($from["adress"]);
         }
     }
     foreach ($realRecipients as $address) {
         if ($address["adress"] == $address["name"]) {
             $mail->AddAddress(trim($address["adress"]));
         } else {
             $mail->AddAddress(trim($address["adress"]), trim($address["name"]));
         }
     }
     $mail->WordWrap = 50;
     // set word wrap to 50 characters
     $mail->IsHTML($useHtml);
     // set email format to HTML
     $mail->CharSet = "utf-8";
     $mail->Encoding = $this->getFilteredOption("MAIL_ENCODING");
     foreach ($images as $image) {
         $mail->AddEmbeddedImage($image["path"], $image["cid"], '', 'base64', 'image/png');
     }
     $mail->Subject = $subject;
     if ($useHtml) {
         if (strpos($body, "<html") !== false) {
             $mail->Body = $body;
         } else {
             $mail->Body = "<html><body>" . nl2br($body) . "</body></html>";
         }
         $mail->AltBody = AjxpMailer::simpleHtml2Text($mail->Body);
     } else {
         $mail->Body = AjxpMailer::simpleHtml2Text($body);
     }
     if (!$mail->Send()) {
         $message = "Message could not be sent\n";
         $message .= "Mailer Error: " . $mail->ErrorInfo;
         throw new Exception($message);
     }
 }
Esempio n. 3
0
 public function sendMail($recipients, $subject, $body, $from = null, $imageLink = null, $useHtml = true)
 {
     $prepend = ConfService::getCoreConf("SUBJECT_PREPEND", "mailer");
     $append = ConfService::getCoreConf("SUBJECT_APPEND", "mailer");
     $layoutFolder = ConfService::getCoreConf("LAYOUT_FOLDER", "mailer");
     $layout = ConfService::getCoreConf("BODY_LAYOUT", "mailer");
     $forceFrom = ConfService::getCoreConf("FORCE_UNIQUE_FROM", "mailer");
     $coreFrom = ConfService::getCoreConf("FROM", "mailer");
     if ($forceFrom && $coreFrom != null) {
         $coreFromName = ConfService::getCoreConf("FROM_NAME", "mailer");
         $from = array("adress" => $coreFrom, "name" => $coreFromName);
     }
     $rowBody = $body;
     $images = array();
     if (!empty($prepend)) {
         $subject = $prepend . " " . $subject;
     }
     if (!empty($append)) {
         $subject .= " " . $append;
     }
     if (!empty($layoutFolder)) {
         $layoutFolder .= "/";
         $lang = ConfService::getLanguage();
         if (!$useHtml) {
             if (is_file(AJXP_INSTALL_PATH . "/" . $layoutFolder . $lang . ".txt")) {
                 $layout = implode("", file(AJXP_INSTALL_PATH . "/" . $layoutFolder . $lang . ".txt"));
             } else {
                 if (is_file(AJXP_INSTALL_PATH . "/" . $layoutFolder . "en.txt")) {
                     $layout = implode("", file(AJXP_INSTALL_PATH . "/" . $layoutFolder . "en.txt"));
                 } else {
                     $layout = "AJXP_MAIL_BODY";
                 }
             }
         } else {
             if (is_file(AJXP_INSTALL_PATH . "/" . $layoutFolder . $lang . ".html")) {
                 $layout = implode("", file(AJXP_INSTALL_PATH . "/" . $layoutFolder . $lang . ".html"));
             } else {
                 if (is_file(AJXP_INSTALL_PATH . "/" . $layoutFolder . "en.html")) {
                     $layout = implode("", file(AJXP_INSTALL_PATH . "/" . $layoutFolder . "en.html"));
                 }
             }
         }
     }
     if (strpos($layout, "AJXP_MAIL_BODY") !== false) {
         $body = str_replace("AJXP_MAIL_BODY", $useHtml ? nl2br($body) : $body, $layout);
     }
     if ($imageLink != null && $useHtml) {
         $body = str_replace(array("AJXP_IMAGE_LINK"), "<a href='" . $imageLink . "'>" . '<img alt="Download" width="100" style="width: 100px;" src="cid:download_id">' . "</a>", $body);
         $images[] = array("path" => AJXP_INSTALL_PATH . "/" . $layoutFolder . "/download.png", "cid" => "download_id");
     } else {
         $body = str_replace(array("AJXP_IMAGE_LINK", "AJXP_IMAGE_END"), "", $body);
     }
     $body = str_replace("AJXP_MAIL_SUBJECT", $subject, $body);
     $this->sendMailImpl($recipients, $subject, $body, $from, $images, $useHtml);
     if (AJXP_SERVER_DEBUG) {
         if (!$useHtml) {
             $rowBody = '[TEXT ONLY] ' . AjxpMailer::simpleHtml2Text($rowBody);
         }
         $line = "------------------------------------------------------------------------\n";
         file_put_contents($this->mailCache, $line . "Sending mail from " . print_r($from, true) . " to " . print_r($recipients, true) . "\nSubject: {$subject}\nBody:\n{$rowBody}\n", FILE_APPEND);
     }
 }