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:      * @param  Message
33:      * @return void
34:      */
35:     public function send(Message $mail)
36:     {
37:         $tmp = clone $mail;
38:         $tmp->setHeader('Subject', NULL);
39:         $tmp->setHeader('To', NULL);
40: 
41:         $parts = explode(Message::EOL . Message::EOL, $tmp->generateMessage(), 2);
42: 
43:         Nette\Diagnostics\Debugger::tryError();
44:         $args = array(
45:             str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('To')),
46:             str_replace(Message::EOL, PHP_EOL, $mail->getEncodedHeader('Subject')),
47:             str_replace(Message::EOL, PHP_EOL, $parts[1]),
48:             str_replace(Message::EOL, PHP_EOL, $parts[0]),
49:         );
50:         if ($this->commandArgs) {
51:             $args[] = (string) $this->commandArgs;
52:         }
53:         $res = call_user_func_array('mail', $args);
54: 
55:         if (Nette\Diagnostics\Debugger::catchError($e)) {
56:             throw new Nette\InvalidStateException('mail(): ' . $e->getMessage(), 0, $e);
57: 
58:         } elseif (!$res) {
59:             throw new Nette\InvalidStateException('Unable to send email.');
60:         }
61:     }
62: 
63: }
64: 
Nette Framework 2.0.3 API API documentation generated by ApiGen 2.7.0