1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Mail;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class SendmailMailer implements IMailer
17: {
18: use Nette\SmartObject;
19:
20:
21: public $commandArgs;
22:
23:
24: 25: 26: 27: 28:
29: public function send(Message $mail)
30: {
31: $tmp = clone $mail;
32: $tmp->setHeader('Subject', null);
33: $tmp->setHeader('To', null);
34:
35: $parts = explode(Message::EOL . Message::EOL, $tmp->generateMessage(), 2);
36:
37: $args = [
38: str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('To')),
39: str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')),
40: str_replace(Message::EOL, PHP_EOL, $parts[1]),
41: str_replace(Message::EOL, PHP_EOL, $parts[0]),
42: ];
43: if ($this->commandArgs) {
44: $args[] = (string) $this->commandArgs;
45: }
46: $res = Nette\Utils\Callback::invokeSafe('mail', $args, function ($message) use (&$info) {
47: $info = ": $message";
48: });
49: if ($res === false) {
50: throw new SendException("Unable to send email$info.");
51: }
52: }
53: }
54: