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.

83 lines
2.4 KiB

  1. <?php
  2. /**
  3. * Класс для отправки мыла
  4. *
  5. * @copyright
  6. * @link
  7. * @package Nakon
  8. * @subpackage face
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. class Mailer
  14. {
  15. public $template_dir = 'mail';
  16. public $template;
  17. public $templater;
  18. public $headers;
  19. function __construct($template)
  20. {
  21. $this->templater = Load::templater(ACTION_TPL_PATH.'/'.$this->template_dir);
  22. $this->template = $template;
  23. /* если че забыл, не серчайте */
  24. $this->headers .= 'From: robot@'.Env::Server('SERVER_NAME');
  25. $this->headers .= "Date: ".$this->RFCDate()."\r\n";
  26. $this->headers .= "From: robot@".Env::Server('SERVER_NAME')."\r\n";
  27. $this->headers .= "Return-Path: robot@".Env::Server('SERVER_NAME')."\r\n";
  28. $this->headers .= "X-Mailer: PHPMail Tool\r\n";
  29. $this->headers .= "Reply-To: robot@".Env::Server('SERVER_NAME')."\r\n";
  30. $this->headers .= "X-Priority: 3 (Normal)\r\n";
  31. $this->headers .= "Message-ID: <". md5(uniqid(time()))."@".Env::Server('SERVER_NAME').">\r\n";
  32. $this->headers .= "MIME-Version: 1.0\r\n";
  33. $this->headers .= "Content-Type: text/plain; charset=windows-1251\r\n";
  34. $this->headers .= "Content-Transfer-Encoding: 8bit\r\n";
  35. }
  36. /**
  37. * Отправляет письма
  38. *
  39. * @param mixed $mail
  40. * @param mixed $subject
  41. * @param mixed $data
  42. */
  43. function send ($mail, $subject, $data)
  44. {
  45. $this->headers .= "To: ".$mail."\r\n";
  46. $this->headers .= "Subject: ".$subject."\r\n";
  47. foreach ($data as $key => $val) {
  48. $this->templater->assign($key, $val);
  49. }
  50. $message = $this->templater->fetch($this->template.'.tpl').'\r\n\r\nС любовью @робот.';
  51. /*
  52. * как только заработает отправка писем на серваке,
  53. * сразу надо раскоментить и проверить
  54. *
  55. * mail($mail, $subject, $message, $this->headers);
  56. */
  57. }
  58. /**
  59. * возвращает дату
  60. *
  61. */
  62. function RFCDate() {
  63. $tz = date("Z");
  64. $tzs = ($tz < 0) ? "-" : "+";
  65. $tz = abs($tz);
  66. $tz = ($tz/3600)*100 + ($tz%3600)/60;
  67. $result = sprintf("%s %s%04d", date("D, j M Y H:i:s"), $tzs, $tz);
  68. return $result;
  69. }
  70. }
  71. ?>