Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • None
  • PHP

Classes

  • Message
  • MimePart
  • SendmailMailer
  • SmtpMailer

Interfaces

  • IMailer

Exceptions

  • SmtpException
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://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 emails via the PHP internal mail() function.
20:  *
21:  * @author     David Grudl
22:  */
23: class SendmailMailer extends Nette\Object implements IMailer
24: {
25:     /** @var string */
26:     public $commandArgs;
27: 
28: 
29: 
30:     /**
31:      * Sends email.
32:      * @return void
33:      */
34:     public function send(Message $mail)
35:     {
36:         $tmp = clone $mail;
37:         $tmp->setHeader('Subject', NULL);
38:         $tmp->setHeader('To', NULL);
39: 
40:         $parts = explode(Message::EOL . Message::EOL, $tmp->generateMessage(), 2);
41: 
42:         Nette\Diagnostics\Debugger::tryError();
43:         $args = array(
44:             str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('To')),
45:             str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')),
46:             str_replace(Message::EOL, PHP_EOL, $parts[1]),
47:             str_replace(Message::EOL, PHP_EOL, $parts[0]),
48:         );
49:         if ($this->commandArgs) {
50:             $args[] = (string) $this->commandArgs;
51:         }
52:         $res = call_user_func_array('mail', $args);
53: 
54:         if (Nette\Diagnostics\Debugger::catchError($e)) {
55:             throw new Nette\InvalidStateException('mail(): ' . $e->getMessage(), 0, $e);
56: 
57:         } elseif (!$res) {
58:             throw new Nette\InvalidStateException('Unable to send email.');
59:         }
60:     }
61: 
62: }
63: 
Nette Framework 2.0.6 API API documentation generated by ApiGen 2.7.0