Namespaces

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • Mail
  • MailMimePart
  • SendmailMailer

Interfaces

  • IMailer
  • Overview
  • Namespace
  • Class
  • Tree
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: namespace Nette\Mail;
13: 
14: use Nette;
15: 
16: 
17: 
18: /**
19:  * Sends e-mails via the PHP internal mail() function.
20:  *
21:  * @author     David Grudl
22:  */
23: class SendmailMailer extends Nette\Object implements IMailer
24: {
25: 
26:     /**
27:      * Sends e-mail.
28:      * @param  Mail
29:      * @return void
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: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0