1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Tracy\Bridges\Nette;
9:
10: use Nette;
11: use Tracy;
12:
13:
14: 15: 16:
17: class MailSender
18: {
19: use Nette\SmartObject;
20:
21:
22: private $mailer;
23:
24:
25: private $fromEmail;
26:
27:
28: public function __construct(Nette\Mail\IMailer $mailer, $fromEmail = null)
29: {
30: $this->mailer = $mailer;
31: $this->fromEmail = $fromEmail;
32: }
33:
34:
35: 36: 37: 38: 39:
40: public function send($message, $email)
41: {
42: $host = preg_replace('#[^\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
43:
44: $mail = new Nette\Mail\Message;
45: $mail->setHeader('X-Mailer', 'Tracy');
46: if ($this->fromEmail || Nette\Utils\Validators::isEmail("noreply@$host")) {
47: $mail->setFrom($this->fromEmail ?: "noreply@$host");
48: }
49: foreach (explode(',', $email) as $item) {
50: $mail->addTo(trim($item));
51: }
52: $mail->setSubject('PHP: An error occurred on the server ' . $host);
53: $mail->setBody(Tracy\Logger::formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource());
54:
55: $this->mailer->send($mail);
56: }
57: }
58: