You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.3 KiB

<?php
/**
* Класс для отправки мыла
*
* @copyright
* @link
* @package Nakon
* @subpackage face
* @since
* @version SVN: $Id$
* @filesource $URL$
*/
class Mailer
{
public $template_dir = 'mail';
public $template;
public $templater;
public $headers;
protected $url;
function __construct($template)
{
$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 .= "Return-Path: robot@". $this->url ."\r\n";
$this->headers .= "X-Mailer: PHPMail Tool\r\n";
$this->headers .= "Reply-To: robot@". $this->url ."\r\n";
$this->headers .= "X-Priority: 3 (Normal)\r\n";
$this->headers .= "Message-ID: <". md5(uniqid(time()))."@". $this->url .">\r\n";
$this->headers .= "MIME-Version: 1.0\r\n";
$this->headers .= "Content-Type: text/plain; charset=utf-8\r\n";
$this->headers .= "Content-Transfer-Encoding: 16bit\r\n";
}
/**
* Отправляет письма
*
* @param mixed $mail
* @param mixed $subject
* @param mixed $data
*/
function send ($mail, $subject, $data)
{
$this->headers .= "To: ".$mail."\r\n";
foreach ($data as $key => $val) {
$this->templater->assign($key, $val);
}
$message = $this->templater->fetch($this->template.'.tpl') . "\r\n\r\nС любовью @робот.";
$encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n";
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;
}
}
?>