Ejemplo n.º 1
0
 function index()
 {
     $mailClass = new Model_Mail();
     if (isset($_GET["filename"])) {
         $filename = $_GET["filename"];
         if (!strpos($filename, "/")) {
             $mid = $_GET["mid"];
             if (isset($_GET["type"]) and $_GET["type"] == "out") {
                 $fn = $mailClass->getFileOut($mid, $filename);
                 $file = $this->registry["rootPublic"] . $this->registry["path"]["upload"] . $fn;
             } else {
                 $fn = $mailClass->getFile($mid, $filename);
                 $file = $this->registry["rootPublic"] . $this->registry["path"]["attaches"] . $fn;
             }
             if (file_exists($file)) {
                 $filename = str_replace(" ", "_", $filename);
                 header("Content-Type: application/octet-stream");
                 header("Accept-Ranges: bytes");
                 header("Content-Length: " . filesize($file));
                 header("Content-Disposition: attachment; filename=" . $filename);
                 readfile($file);
             } else {
                 $this->view->setTitle("Файл не найден");
                 $this->view->setMainContent("<p style='text-align: center'>Файл не найден</p>");
                 $this->view->refresh(array("timer" => "1", "url" => ""));
             }
         }
     }
 }
Ejemplo n.º 2
0
 function phpmailer($post, $smtp = null, $fromName = null)
 {
     $settings = new Model_Settings($this->registry);
     $mailClass = new Model_Mail();
     if ($smtp == null) {
         $smtp = $settings->getMailbox();
     }
     if ($fromName == null) {
         $fromName = $this->registry["mailSenderName"];
     }
     $mailer = new Phpmailer_Phpmailer();
     $err = array();
     $mailer->SMTPDebug = 0;
     $mailer->CharSet = "utf-8";
     $mailer->IsSMTP();
     $mailer->Host = $smtp["server"];
     $mailer->Port = $smtp["port"];
     if ($smtp["ssl"] == "ssl") {
         $mailer->SMTPSecure = "ssl";
     }
     if ($smtp["login"] and $smtp["password"]) {
         $mailer->SMTPAuth = true;
         $mailer->Username = $smtp["login"];
         $mailer->Password = $smtp["password"];
     } else {
         $mailer->SMTPAuth = false;
     }
     $mailer->From = $smtp["email"];
     $mailer->FromName = $fromName;
     if ($post["to"] == null) {
         $err[] = "Не заданы адресаты";
     } else {
         $to = explode(",", $post["to"]);
         for ($i = 0; $i < count($to); $i++) {
             $mailer->AddAddress($to[$i]);
         }
     }
     if (isset($post["attaches"])) {
         foreach ($post["attaches"] as $part) {
             $filename = mb_substr($part, mb_strrpos($part, DIRECTORY_SEPARATOR) + 1, mb_strlen($part) - mb_strrpos($part, DIRECTORY_SEPARATOR));
             if (substr($part, 0, 1) != "/") {
                 $dir = $this->registry["path"]["upload"];
                 $md5 = $mailClass->getAttachFileMD5($part);
             } else {
                 if (isset($post["mail"]) and $post["mail"]) {
                     $dir = $this->registry["path"]["attaches"];
                     $md5 = $mailClass->getFile($post["mail_id"], $filename);
                 } else {
                     $dir = $this->registry["path"]["upload"];
                     $md5 = $mailClass->getFileMD5($part);
                 }
             }
             $mailer->AddAttachment($this->registry["rootPublic"] . $dir . $md5, $filename);
         }
     }
     if (!$this->text) {
         $mailer->IsHTML(true);
         $mailer->Subject = $post["subject"];
         $mailer->Body = $post["textfield"];
         $mailer->AltBody = strip_tags($post["textfield"]);
     } else {
         $mailer->IsHTML(false);
         $mailer->Subject = base64_encode($post["subject"]);
         $mailer->Body = base64_encode($post["textfield"]);
     }
     if ($post["textfield"] == null) {
         $err[] = "Пустое письмо";
     }
     if (count($err) == 0) {
         if (!$mailer->Send()) {
             return $mailer->ErrorInfo;
         } else {
             return false;
         }
     } else {
         return $err;
     }
 }