From a334d80706dfb7f79d35cc68fa1fad8829eb6df9 Mon Sep 17 00:00:00 2001 From: ejikharev Date: Mon, 8 Dec 2008 10:32:54 +0000 Subject: [PATCH] class mailer for send mail git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@20 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Mailer.class.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 classes/Mailer.class.php diff --git a/classes/Mailer.class.php b/classes/Mailer.class.php new file mode 100644 index 0000000..b778606 --- /dev/null +++ b/classes/Mailer.class.php @@ -0,0 +1,84 @@ +templater = Load::templater(ACTION_TPL_PATH.'/'.$this->template_dir); + $this->template = $template; + + /* если че забыл, не серчайте */ + $this->headers .= 'From: robot@'.Env::Server('SERVER_NAME'); + $this->headers .= "Date: ".$this->RFCDate()."\r\n"; + $this->headers .= "From: robot@".Env::Server('SERVER_NAME')."\r\n"; + $this->headers .= "Return-Path: robot@".Env::Server('SERVER_NAME')."\r\n"; + $this->headers .= "X-Mailer: PHPMail Tool\r\n"; + $this->headers .= "Reply-To: robot@".Env::Server('SERVER_NAME')."\r\n"; + $this->headers .= "X-Priority: 3 (Normal)\r\n"; + $this->headers .= "Message-ID: <". md5(uniqid(time()))."@".Env::Server('SERVER_NAME').">\r\n"; + $this->headers .= "MIME-Version: 1.0\r\n"; + $this->headers .= "Content-Type: text/plain; charset=windows-1251\r\n"; + $this->headers .= "Content-Transfer-Encoding: 8bit\r\n"; + } + + + /** + * Отправляет письма + * + * @param mixed $mail + * @param mixed $subject + * @param mixed $data + */ + function send ($mail, $subject, $data) + { + $this->headers .= "To: ".$mail."\r\n"; + $this->headers .= "Subject: ".$subject."\r\n"; + + foreach ($data as $key => $val) { + $this->templater->assign($key, $val); + } + + $message = $this->templater->fetch($this->template.'.tpl').'\r\n\r\nС любовью @робот.'; + + /* + * как только заработает отправка писем на серваке, + * сразу надо раскоментить и проверить + * + * mail($mail, $subject, $message, $this->headers); + */ + } + + + /** + * возвращает дату + * + */ + function RFCDate() { + $tz = date("Z"); + $tzs = ($tz < 0) ? "-" : "+"; + $tz = abs($tz); + $tz = ($tz/3600)*100 + ($tz%3600)/60; + $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz); + + return $result; + } + +} + +?> \ No newline at end of file