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: 25: 26: 27: 28:
29: public function send(NMail $mail)
30: {
31: $tmp = clone $mail;
32: $tmp->setHeader('Subject', NULL);
33: $tmp->setHeader('To', NULL);
34:
35: $parts = explode(NMail::EOL . NMail::EOL, $tmp->generateMessage(), 2);
36:
37: NTools::tryError();
38: $res = mail(
39: str_replace(NMail::EOL, PHP_EOL, $mail->getEncodedHeader('To')),
40: str_replace(NMail::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')),
41: str_replace(NMail::EOL, PHP_EOL, $parts[1]),
42: str_replace(NMail::EOL, PHP_EOL, $parts[0])
43: );
44:
45: if (NTools::catchError($msg)) {
46: throw new InvalidStateException($msg);
47:
48: } elseif (!$res) {
49: throw new InvalidStateException('Unable to send email.');
50: }
51: }
52:
53: }
54: