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