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.

80 lines
2.4 KiB

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