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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:     /**
30:      * Send mail
31:      *
32:      * @param \Cake\Mailer\Email $email Cake Email
33:      * @return array
34:      */
35:     public function send(Email $email)
36:     {
37:         $eol = PHP_EOL;
38:         if (isset($this->_config['eol'])) {
39:             $eol = $this->_config['eol'];
40:         }
41:         $headers = $email->getHeaders(['from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc']);
42:         $to = $headers['To'];
43:         unset($headers['To']);
44:         foreach ($headers as $key => $header) {
45:             $headers[$key] = str_replace(["\r", "\n"], '', $header);
46:         }
47:         $headers = $this->_headersToString($headers, $eol);
48:         $subject = str_replace(["\r", "\n"], '', $email->getSubject());
49:         $to = str_replace(["\r", "\n"], '', $to);
50: 
51:         $message = implode($eol, $email->message());
52: 
53:         $params = isset($this->_config['additionalParameters']) ? $this->_config['additionalParameters'] : null;
54:         $this->_mail($to, $subject, $message, $headers, $params);
55: 
56:         $headers .= $eol . 'To: ' . $to;
57:         $headers .= $eol . 'Subject: ' . $subject;
58: 
59:         return ['headers' => $headers, 'message' => $message];
60:     }
61: 
62:     /**
63:      * Wraps internal function mail() and throws exception instead of errors if anything goes wrong
64:      *
65:      * @param string $to email's recipient
66:      * @param string $subject email's subject
67:      * @param string $message email's body
68:      * @param string $headers email's custom headers
69:      * @param string|null $params additional params for sending email
70:      * @throws \Cake\Network\Exception\SocketException if mail could not be sent
71:      * @return void
72:      */
73:     protected function _mail($to, $subject, $message, $headers, $params = null)
74:     {
75:         //@codingStandardsIgnoreStart
76:         if (!@mail($to, $subject, $message, $headers, $params)) {
77:             $error = error_get_last();
78:             $msg = 'Could not send email: ' . (isset($error['message']) ? $error['message'] : 'unknown');
79:             throw new SocketException($msg);
80:         }
81:         //@codingStandardsIgnoreEnd
82:     }
83: }
84: 
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