Beispiel #1
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;
     }
 }
Beispiel #2
0
 function getFileMD5($params)
 {
     $mailClass = new Model_Mail();
     return $mailClass->getFileMD5($params[0]);
 }