CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • DebugTransport
  • MailTransport
  • SmtpTransport
 1: <?php
 2: /**
 3:  * Send mail using mail() function
 4:  *
 5:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 6:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 7:  *
 8:  * Licensed under The MIT License
 9:  * For full copyright and license information, please see the LICENSE.txt
10:  * Redistributions of files must retain the above copyright notice.
11:  *
12:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
13:  * @link          https://cakephp.org CakePHP(tm) Project
14:  * @since         2.0.0
15:  * @license       https://opensource.org/licenses/mit-license.php MIT License
16:  */
17: namespace Cake\Mailer\Transport;
18: 
19: use Cake\Mailer\AbstractTransport;
20: use Cake\Mailer\Email;
21: use Cake\Network\Exception\SocketException;
22: 
23: /**
24:  * Send mail using mail() function
25:  */
26: class MailTransport extends AbstractTransport
27: {
28:     /**
29:      * Send mail
30:      *
31:      * @param \Cake\Mailer\Email $email Cake Email
32:      * @return array
33:      */
34:     public function send(Email $email)
35:     {
36:         $eol = PHP_EOL;
37:         if (isset($this->_config['eol'])) {
38:             $eol = $this->_config['eol'];
39:         }
40:         $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']);
41:         $to = $headers['To'];
42:         unset($headers['To']);
43:         foreach ($headers as $key => $header) {
44:             $headers[$key] = str_replace(["\r", "\n"], '', $header);
45:         }
46:         $headers = $this->_headersToString($headers, $eol);
47:         $subject = str_replace(["\r", "\n"], '', $email->getSubject());
48:         $to = str_replace(["\r", "\n"], '', $to);
49: 
50:         $message = implode($eol, $email->message());
51: 
52:         $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
53:         $this->_mail($to, $subject, $message, $headers, $params);
54: 
55:         $headers .= $eol . 'To: ' . $to;
56:         $headers .= $eol . 'Subject: ' . $subject;
57: 
58:         return ['headers' => $headers, 'message' => $message];
59:     }
60: 
61:     /**
62:      * Wraps internal function mail() and throws exception instead of errors if anything goes wrong
63:      *
64:      * @param string $to email's recipient
65:      * @param string $subject email's subject
66:      * @param string $message email's body
67:      * @param string $headers email's custom headers
68:      * @param string|null $params additional params for sending email
69:      * @throws \Cake\Network\Exception\SocketException if mail could not be sent
70:      * @return void
71:      */
72:     protected function _mail($to, $subject, $message, $headers, $params = null)
73:     {
74:         //@codingStandardsIgnoreStart
75:         if (!@mail($to, $subject, $message, $headers, $params)) {
76:             $error = error_get_last();
77:             $msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
78:             throw new SocketException($msg);
79:         }
80:         //@codingStandardsIgnoreEnd
81:     }
82: }
83: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs