Packages

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

Classes

  • NMail
  • NMailMimePart
  • NSendmailMailer

Interfaces

  • IMailer
  • Overview
  • Package
  • 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:  * @package Nette\Mail
11:  */
12: 
13: 
14: 
15: /**
16:  * Sends e-mails via the PHP internal mail() function.
17:  *
18:  * @author     David Grudl
19:  * @package Nette\Mail
20:  */
21: class NSendmailMailer extends NObject implements IMailer
22: {
23: 
24:     /**
25:      * Sends e-mail.
26:      * @param  NMail
27:      * @return void
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: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0