Browse Source

email sending changes

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@73 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
master
pzinovkin 16 years ago
parent
commit
aa4dc5ab19
  1. 30
      classes/Mailer.class.php
  2. 20
      classes/User.class.php

30
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)
{
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);
}
/**
* возвращает дату
* Отправка письма с непосредственным указанием контента
*
* @param string $email
* @param string $subject
* @param string $content
* @return bool
*/
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;
public function sendMessage($email, $subject, $content)
{
$encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n";
return mail($email, $encoded_subject, $content, $this->headers);
}
}
?>

20
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(
$text = new SettingsTextModel();
$message = $text->getText('mail_activate');
$replaces = array(
'link' => $link,
'site_name' => $settings['site_url'],
'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);
}
}
?>
Loading…
Cancel
Save