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