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