public function index() { if ($this->registry["ui"]["admin"]) { $this->view->setTitle("Настройки почты"); $this->view->setLeftContent($this->view->render("left_settings", array())); $settings = new Model_Settings(); if (isset($_POST["submit"])) { $flag = true; if ($_POST["email"] == "") { $flag = false; } if ($_POST["server"] == "") { $flag = false; } if ($_POST["auth"] == "0") { $_POST["login"] = ""; $_POST["password"] = ""; } else { if ($_POST["login"] == "") { $flag = false; } if ($_POST["password"] == "") { $flag = false; } } if ($_POST["port"] == "") { $flag = false; } if ($_POST["ssl"] == "") { $flag = false; } if ($flag) { $settings->editMailbox($_POST); $this->view->refresh(array("timer" => "1", "url" => "settings/mail/")); } else { $this->view->settings_mail(array("err" => true, "post" => $_POST)); } } else { $mailboxes = $settings->getMailbox(); $this->view->settings_mail(array("post" => $mailboxes)); } } }
function phpmailer($_POST, $smtp = null, $fromName = null) { $settings = new Model_Settings($this->registry); if (isset($this->registry["module_mail"])) { $mailClass = $this->registry["module_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; } }
function mailAction($mail) { $ttmail = new Model_TtMail(); $ttmail->uid = $this->uid; $settings = new Model_Settings(); $otms_mail = $settings->getMailbox(); $json = json_decode(base64_decode($mail["subject"])); if ($json->name == "OTMS" and isset($json->method)) { $this->emailTask = true; if ($otms_mail["email"] != $mail["mailbox"] . "@" . $mail["host"]) { if ($json->method == "addtask") { $this->textMailAction = "Новая задача(другая OTMS)"; foreach ($mail["body"] as $part) { $part = json_decode(base64_decode($part["text"]), true); $tid = $ttmail->addTask($json->tid, $part); } foreach ($mail["attach"] as $key => $part) { if ($part != "") { $sql = "INSERT INTO mail_attach (tid, md5, filename) VALUES (:tid, :md5, :filename)"; $res = $this->registry['db']->prepare($sql); $param = array(":tid" => $tid, ":md5" => $key, ":filename" => $part); $res->execute($param); } } } elseif ($json->method == "edittask") { $this->textMailAction = "Правка задачи(другая OTMS)"; foreach ($mail["body"] as $part) { $part = json_decode(base64_decode($part["text"]), true); $tid = $ttmail->editTask($json->tid, $part); } if (isset($mail["attach"]) and count($mail["attach"]) > 0) { $sql = "DELETE FROM mail_attach WHERE tid = :tid"; $res = $this->registry['db']->prepare($sql); $param = array(":mid" => $tid); $res->execute($param); } foreach ($mail["attach"] as $key => $part) { if ($part != "") { $sql = "INSERT INTO mail_attach (tid, md5, filename) VALUES (:tid, :md5, :filename)"; $res = $this->registry['db']->prepare($sql); $param = array(":tid" => $tid, ":md5" => $key, ":filename" => $part); $res->execute($param); } } } elseif ($json->method == "closetask") { $this->textMailAction = "Задача закрыта(другая OTMS)"; $ttmail->closeTask($json->tid); } elseif ($json->method == "comment") { $this->textMailAction = "Комментарий к задаче(другая OTMS)"; foreach ($mail["body"] as $part) { $part = json_decode(base64_decode($part["text"]), true); if ($json->rc) { $tdid = $ttmail->addCommentAnswer($json->tid, $part, $part["status"]); } else { $tdid = $ttmail->addComment($json->tid, $part, $part["status"]); } } foreach ($mail["attach"] as $key => $part) { if ($part != "") { $sql = "INSERT INTO mail_attach (tdid, md5, filename) VALUES (:tdid, :md5, :filename)"; $res = $this->registry['db']->prepare($sql); $param = array(":tdid" => $tdid, ":md5" => $key, ":filename" => $part); $res->execute($param); } } } } else { $this->notLog = false; } } }