NativeMailerHandler.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\Logger;
  12. /**
  13. * NativeMailerHandler uses the mail() function to send the emails
  14. *
  15. * @author Christophe Coevoet <stof@notk.org>
  16. */
  17. class NativeMailerHandler extends MailHandler
  18. {
  19. protected $to;
  20. protected $subject;
  21. protected $headers;
  22. /**
  23. * @param string $to The receiver of the mail
  24. * @param string $subject The subject of the mail
  25. * @param string $from The sender of the mail
  26. * @param integer $level The minimum logging level at which this handler will be triggered
  27. * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
  28. */
  29. public function __construct($to, $subject, $from, $level = Logger::ERROR, $bubble = true)
  30. {
  31. parent::__construct($level, $bubble);
  32. $this->to = $to;
  33. $this->subject = $subject;
  34. $this->headers = sprintf("From: %s\r\nContent-type: text/plain; charset=utf-8\r\n", $from);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. protected function send($content)
  40. {
  41. mail($this->to, $this->subject, wordwrap($content, 120), $this->headers);
  42. }
  43. }