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