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