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: public function send(NMail $mail)
33: {
34: $tmp = clone $mail;
35: $tmp->setHeader('Subject', NULL);
36: $tmp->setHeader('To', NULL);
37:
38: $parts = explode(NMail::EOL . NMail::EOL, $tmp->generateMessage(), 2);
39:
40: NDebugger::tryError();
41: $args = array(
42: str_replace(NMail::EOL, PHP_EOL, $mail->getEncodedHeader('To')),
43: str_replace(NMail::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')),
44: str_replace(NMail::EOL, PHP_EOL, $parts[1]),
45: str_replace(NMail::EOL, PHP_EOL, $parts[0]),
46: );
47: if ($this->commandArgs) {
48: $args[] = (string) $this->commandArgs;
49: }
50: $res = call_user_func_array('mail', $args);
51:
52: if (NDebugger::catchError($e)) {
53: throw new InvalidStateException('mail(): ' . $e->getMessage(), 0, $e);
54:
55: } elseif (!$res) {
56: throw new InvalidStateException('Unable to send email.');
57: }
58: }
59:
60: }
61: