From aa4dc5ab19ab3f2ed87b6a26578b7c36bdf07763 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Tue, 14 Apr 2009 08:07:40 +0000 Subject: [PATCH] email sending changes git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@73 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Mailer.class.php | 38 ++++++++++++++++++-------------------- classes/User.class.php | 22 +++++++++++++++++----- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/classes/Mailer.class.php b/classes/Mailer.class.php index 8a7bb5e..da0f508 100644 --- a/classes/Mailer.class.php +++ b/classes/Mailer.class.php @@ -14,23 +14,24 @@ class Mailer { public $template_dir = 'mail'; - public $template; + public $template = null; public $templater; public $headers; protected $url; - function __construct($template) + function __construct($template = null) { - $this->templater = Load::templater(ACTION_TPL_PATH.'/'.$this->template_dir); - $this->template = $template; + if ($template !== null) { + $this->templater = Load::templater(ACTION_TPL_PATH.'/'.$this->template_dir); + $this->template = $template; + } $settings = Env::getParam('site_settings'); $this->url = $settings['host_name']; /* если че забыл, не серчайте */ $this->headers .= 'From: robot@' . $this->url . "\r\n"; - $this->headers .= "Date: ".$this->RFCDate()."\r\n"; - $this->headers .= "From: robot@". $this->url ."\r\n"; + $this->headers .= 'Date: '. date('r') ."\r\n"; $this->headers .= "Return-Path: robot@". $this->url ."\r\n"; $this->headers .= "X-Mailer: PHPMail Tool\r\n"; $this->headers .= "Reply-To: robot@". $this->url ."\r\n"; @@ -62,21 +63,18 @@ class Mailer return 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; + * Отправка письма с непосредственным указанием контента + * + * @param string $email + * @param string $subject + * @param string $content + * @return bool + */ + public function sendMessage($email, $subject, $content) + { + $encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n"; + return mail($email, $encoded_subject, $content, $this->headers); } - } - ?> \ No newline at end of file diff --git a/classes/User.class.php b/classes/User.class.php index 01c9802..2cdef44 100644 --- a/classes/User.class.php +++ b/classes/User.class.php @@ -131,12 +131,24 @@ class User $model = new UserActivateModel(); $link = 'http://' . $settings['host_name'] . '/activate/?key=' . $model->generateKey($login, $mail); - $mailer = new Mailer('UserRegister'); - return $mailer->send($mail, 'Подтверждени E-mail ' . $settings['host_name'], array( - 'link' => $link, - 'site_name' => $settings['site_url'], + $text = new SettingsTextModel(); + $message = $text->getText('mail_activate'); + + $replaces = array( + 'link' => $link, + 'host' => $settings['site_url'], 'email' => $mail, - )); + ); + + if (!$message) { + return false; + } + + foreach ($replaces as $key => $val) { + $message->text = str_replace('%' . $key . '%', $val, $message->text); + } + $mailer = new Mailer(); + return $mailer->sendMessage($mail, 'Подтверждение E-mail ' . $settings['host_name'], $message->text); } } ?> \ No newline at end of file