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.

78 lines
2.3 KiB

  1. <?php
  2. /**
  3. * Класс для отправки почты
  4. *
  5. * @copyright NetMonsters <team@netmonsters.ru>
  6. * @link http://netmonsters.ru
  7. * @package Core
  8. * @subpackage mail
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. class Mailer
  14. {
  15. public $template_dir = 'mail';
  16. public $template = null;
  17. public $templater;
  18. public $headers;
  19. protected $host;
  20. function __construct($host, $template = null)
  21. {
  22. if ($template !== null) {
  23. $this->templater = Load::templater(ACTION_TPL_PATH . '/' . $this->template_dir);
  24. $this->template = $template;
  25. }
  26. $this->host = $host;
  27. $this->headers .= 'From: robot@' . $this->host . "\r\n";
  28. $this->headers .= 'Date: '. date('r') ."\r\n";
  29. $this->headers .= "Return-Path: robot@". $this->host ."\r\n";
  30. $this->headers .= "X-Mailer: PHPMail Tool\r\n";
  31. $this->headers .= "Reply-To: robot@". $this->host ."\r\n";
  32. $this->headers .= "X-Priority: 3 (Normal)\r\n";
  33. $this->headers .= "Message-ID: <". md5(uniqid(time()))."@". $this->host .">\r\n";
  34. $this->headers .= "MIME-Version: 1.0\r\n";
  35. $this->headers .= "Content-Type: text/plain; charset=utf-8\r\n";
  36. $this->headers .= "Content-Transfer-Encoding: 16bit\r\n";
  37. }
  38. /**
  39. * Отправляет письма
  40. *
  41. * @param mixed $mail
  42. * @param mixed $subject
  43. * @param mixed $data
  44. */
  45. function send ($mail, $subject, $data)
  46. {
  47. $this->headers .= "To: ".$mail."\r\n";
  48. foreach ($data as $key => $val) {
  49. $this->templater->assign($key, $val);
  50. }
  51. $message = $this->templater->fetch($this->template.'.tpl');
  52. $encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n";
  53. return mail($mail, $subject, $message, $this->headers);
  54. }
  55. /**
  56. * Отправка письма с непосредственным указанием контента
  57. *
  58. * @param string $email
  59. * @param string $subject
  60. * @param string $content
  61. * @return bool
  62. */
  63. public function sendMessage($email, $subject, $content)
  64. {
  65. $encoded_subject = '=?UTF-8?B?' . base64_encode($subject) . "?=\r\n";
  66. return mail($email, $encoded_subject, $content, $this->headers);
  67. }
  68. }
  69. ?>