CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.2 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 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

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • I18n
    • Log
    • Mailer
      • Exception
      • Transport
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class Email

CakePHP Email class.

This class is used for sending Internet Message Format based on the standard outlined in http://www.rfc-editor.org/rfc/rfc2822.txt

Configuration

Configuration for Email is managed by Email::config() and Email::configTransport(). Email::config() can be used to add or read a configuration profile for Email instances. Once made configuration profiles can be used to re-use across various email messages your application sends.

Namespace: Cake\Mailer

Constants

  • string
    EMAIL_PATTERN ¶
    '/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-.]+)$/ui'

    Holds the regex pattern for email validation

  • int
    LINE_LENGTH_MUST ¶
    998

    Line length - no must more - RFC 2822 - 2.1.1

  • int
    LINE_LENGTH_SHOULD ¶
    78

    Line length - no should more - RFC 2822 - 2.1.1

  • string
    MESSAGE_HTML ¶
    'html'

    Type of message - HTML

  • string
    MESSAGE_TEXT ¶
    'text'

    Type of message - TEXT

Property Summary

  • $_appCharset protected
    string

    The application wide charset, used to encode headers and body

  • $_attachments protected
    array

    List of files that should be attached to the email.

  • $_bcc protected
    array

    Blind Carbon Copy

  • $_boundary protected
    string

    If set, boundary to use for multipart mime messages

  • $_cc protected
    array

    Carbon Copy

  • $_charset8bit protected
    array

    8Bit character sets

  • $_config protected static
    array

    Configuration sets.

  • $_contentTypeCharset protected
    array

    Define Content-Type charset name

  • $_domain protected
    string

    Domain for messageId generation. Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty

  • $_dsnClassMap protected static
    array

    An array mapping url schemes to fully qualified Transport class names

  • $_emailFormat protected
    string

    What format should the email be sent in

  • $_emailFormatAvailable protected
    array

    Available formats to be sent.

  • $_emailPattern protected
    string

    Regex for email validation

  • $_from protected
    array

    The mail which the email is sent from

  • $_headers protected
    array

    Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5

  • $_htmlMessage protected
    string

    Html message

  • $_message protected
    array

    Final message to send

  • $_messageId protected
    bool|string

    Message ID

  • $_profile protected
    array

    A copy of the configuration profile for this instance. This copy can be modified with Email::profile().

  • $_readReceipt protected
    array

    The read receipt email

  • $_replyTo protected
    array

    The email the recipient will reply to

  • $_returnPath protected
    array

    The mail that will be used in case of any errors like

    • Remote mailserver down
    • Remote user has exceeded his quota
    • Unknown user
  • $_sender protected
    array

    The sender email

  • $_subject protected
    string

    The subject of the email

  • $_textMessage protected
    string

    Text message

  • $_to protected
    array

    Recipient of the email

  • $_transport protected
    Cake\Mailer\AbstractTransport

    The transport instance to use for sending mail.

  • $_transportConfig protected static
    array

    Configuration profiles for transports.

  • $_viewBuilder protected
    Cake\View\ViewBuilder

    The view builder instance being used.

  • $charset public
    string

    Charset the email body is sent in

  • $headerCharset public
    string

    Charset the email header is sent in If null, the $charset property will be used as default

  • $viewClass public deprecated
    string

    The name of default View class.

  • $viewVars public
    array

    Variables for the view

Method Summary

  • __clone() public

    Clone ViewBuilder instance when email object is cloned.

  • __construct() public

    Constructor

  • _addEmail() protected

    Add email

  • _applyConfig() protected

    Apply the config to an instance

  • _attachFiles() protected

    Attach non-embedded files by adding file contents inside boundaries.

  • _attachInlineFiles() protected

    Attach inline/embedded files to the message.

  • _checkViewVars() protected

    Iterates through hash to clean up and normalize.

  • _constructTransport() protected

    Build a transport instance from configuration data.

  • _createBoundary() protected

    Create unique boundary identifier

  • _encode() protected

    Encode the specified string using the current charset

  • _encodeString() protected

    Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists

  • _formatAddress() protected

    Format addresses

  • _getContentTransferEncoding() protected

    Return the Content-Transfer Encoding value based on the set charset

  • _getContentTypeCharset() protected

    Return charset value for Content-Type.

  • _getTypes() protected

    Gets the text body types that are in this email message

  • _logDelivery() protected

    Log the email message delivery.

  • _readFile() protected

    Read the file contents and return a base64 version of the file contents.

  • _render() protected

    Render the body of the email.

  • _renderTemplates() protected

    Build and set all the view properties needed to render the templated emails. If there is no template set, the $content will be returned in a hash of the text content types for the email.

  • _setEmail() protected

    Set email

  • _setEmailSingle() protected

    Set only 1 email

  • _validateEmail() protected

    Validate email address

  • _wrap() protected

    Wrap the message to follow the RFC 2822 - 2.1.1

  • addAttachments() public

    Add attachments

  • addBcc() public

    Add Bcc

  • addCc() public

    Add Cc

  • addHeaders() public

    Add header for the message

  • addTo() public

    Add To

  • attachments() public

    Add attachments to the email message

  • bcc() public

    Bcc

  • cc() public

    Cc

  • charset() public

    Charset setter/getter

  • config() public static

    This method can be used to define configuration adapters for an application or read existing configuration.

  • configTransport() public static

    Add or read transport configuration.

  • configured() public static

    Returns an array containing the named configurations

  • configuredTransport() public static

    Returns an array containing the named transport configurations

  • createFromArray() public

    Configures an email instance object from serialized config.

  • createView() public

    Constructs the view class instance based on the current configuration.

  • deliver() public static

    Static method to fast create an instance of \Cake\Mailer\Email

  • domain() public

    Domain as top level (the part after @)

  • drop() public static

    Drops a constructed adapter.

  • dropTransport() public static

    Delete transport configuration.

  • dsnClassMap() public static

    Returns or updates the DSN class map for this class

  • emailFormat() public

    Email format

  • emailPattern() public

    EmailPattern setter/getter

  • from() public

    From

  • getHeaders() public

    Get list of headers

  • headerCharset() public

    HeaderCharset setter/getter

  • helpers() public

    Helpers to be used in render

  • jsonSerialize() public

    Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.

  • message() public

    Get generated message (used by transport classes)

  • messageId() public

    Message-ID

  • parseDsn() public static

    Parses a DSN into a valid connection configuration

  • profile() public

    Get/Set the configuration profile to use for this instance.

  • readReceipt() public

    Read Receipt (Disposition-Notification-To header)

  • replyTo() public

    Reply-To

  • reset() public

    Reset all the internal variables to be able to send out a new email.

  • returnPath() public

    Return Path

  • send() public

    Send an email using the specified content, template and layout

  • sender() public

    Sender

  • serialize() public

    Serializes the Email object.

  • set() public

    Saves a variable or an associative array of variables for use inside a template.

  • setHeaders() public

    Sets headers for the message

  • subject() public

    Get/Set Subject.

  • template() public

    Template and layout

  • theme() public

    Theme to use when rendering

  • to() public

    To

  • transport() public

    Get/set the transport.

  • unserialize() public

    Unserializes the Email object.

  • viewBuilder() public

    Get the view builder being used.

  • viewOptions() public

    Get/Set valid view options in the object's _validViewOptions property. The property is created as an empty array if it is not set. If called without any parameters it will return the current list of valid view options. See createView().

  • viewRender() public

    View class for render

  • viewVars() public

    Variables to be set on render

Method Detail

__clone() ¶ public

__clone(): void

Clone ViewBuilder instance when email object is cloned.

Returns
void

__construct() ¶ public

__construct(array|string|null $config = null)

Constructor

Parameters
array|string|null $config optional

Array of configs, or string to load configs from email.php

_addEmail() ¶ protected

_addEmail(string $varName, string|array $email, string $name): $this

Add email

Parameters
string $varName

Property name

string|array $email

String with email, Array with email as key, name as value or email as value (without name)

string $name

Name

Returns
$this
Throws
InvalidArgumentException

_applyConfig() ¶ protected

_applyConfig(string|array $config): void

Apply the config to an instance

Parameters
string|array $config

Configuration options.

Returns
void
Throws
InvalidArgumentException
When using a configuration that doesn't exist.

_attachFiles() ¶ protected

_attachFiles(string|null $boundary = null): array

Attach non-embedded files by adding file contents inside boundaries.

Parameters
string|null $boundary optional

Boundary to use. If null, will default to $this->_boundary

Returns
array

_attachInlineFiles() ¶ protected

_attachInlineFiles(string|null $boundary = null): array

Attach inline/embedded files to the message.

Parameters
string|null $boundary optional

Boundary to use. If null, will default to $this->_boundary

Returns
array

_checkViewVars() ¶ protected

_checkViewVars(mixed $item, string $key): void

Iterates through hash to clean up and normalize.

Parameters
mixed $item

Reference to the view var value.

string $key

View var key.

Returns
void

_constructTransport() ¶ protected

_constructTransport(string $name): Cake\Mailer\AbstractTransport

Build a transport instance from configuration data.

Parameters
string $name

The transport configuration name to build.

Returns
Cake\Mailer\AbstractTransport
Throws
InvalidArgumentException
When transport configuration is missing or invalid.

_createBoundary() ¶ protected

_createBoundary(): void

Create unique boundary identifier

Returns
void

_encode() ¶ protected

_encode(string $text): string

Encode the specified string using the current charset

Parameters
string $text

String to encode

Returns
string

_encodeString() ¶ protected

_encodeString(string $text, string $charset): string

Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists

Parameters
string $text

The text to be converted

string $charset

the target encoding

Returns
string

_formatAddress() ¶ protected

_formatAddress(array $address): array

Format addresses

If the address contains non alphanumeric/whitespace characters, it will be quoted as characters like : and , are known to cause issues in address header fields.

Parameters
array $address

Addresses to format.

Returns
array

_getContentTransferEncoding() ¶ protected

_getContentTransferEncoding(): string

Return the Content-Transfer Encoding value based on the set charset

Returns
string

_getContentTypeCharset() ¶ protected

_getContentTypeCharset(): string

Return charset value for Content-Type.

Checks fallback/compatibility types which include workarounds for legacy japanese character sets.

Returns
string

_getTypes() ¶ protected

_getTypes(): array

Gets the text body types that are in this email message

Returns
array

_logDelivery() ¶ protected

_logDelivery(array $contents): void

Log the email message delivery.

Parameters
array $contents

The content with 'headers' and 'message' keys.

Returns
void

_readFile() ¶ protected

_readFile(string $path): string

Read the file contents and return a base64 version of the file contents.

Parameters
string $path

The absolute path to the file to read.

Returns
string

_render() ¶ protected

_render(array $content): array

Render the body of the email.

Parameters
array $content

Content to render

Returns
array

_renderTemplates() ¶ protected

_renderTemplates(string $content): array

Build and set all the view properties needed to render the templated emails. If there is no template set, the $content will be returned in a hash of the text content types for the email.

Parameters
string $content

The content passed in from send() in most cases.

Returns
array

_setEmail() ¶ protected

_setEmail(string $varName, string|array $email, string $name): $this

Set email

Parameters
string $varName

Property name

string|array $email

String with email, Array with email as key, name as value or email as value (without name)

string $name

Name

Returns
$this
Throws
InvalidArgumentException

_setEmailSingle() ¶ protected

_setEmailSingle(string $varName, string|array $email, string $name, string $throwMessage): $this

Set only 1 email

Parameters
string $varName

Property name

string|array $email

String with email, Array with email as key, name as value or email as value (without name)

string $name

Name

string $throwMessage

Exception message

Returns
$this
Throws
InvalidArgumentException

_validateEmail() ¶ protected

_validateEmail(string $email): void

Validate email address

Parameters
string $email

Email address to validate

Returns
void
Throws
InvalidArgumentException
If email address does not validate

_wrap() ¶ protected

_wrap(string $message, int $wrapLength = Email::LINE_LENGTH_MUST): array

Wrap the message to follow the RFC 2822 - 2.1.1

Parameters
string $message

Message to wrap

int $wrapLength optional

The line length

Returns
array

addAttachments() ¶ public

addAttachments(string|array $attachments): $this

Add attachments

Parameters
string|array $attachments

String with the filename or array with filenames

Returns
$this
Throws
InvalidArgumentException
See Also
\Cake\Mailer\Email::attachments()

addBcc() ¶ public

addBcc(string|array $email, string|null $name = null): $this

Add Bcc

Parameters
string|array $email

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
$this

addCc() ¶ public

addCc(string|array $email, string|null $name = null): $this

Add Cc

Parameters
string|array $email

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
$this

addHeaders() ¶ public

addHeaders(array $headers): $this

Add header for the message

Parameters
array $headers

Headers to set.

Returns
$this

addTo() ¶ public

addTo(string|array $email, string|null $name = null): $this

Add To

Parameters
string|array $email

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
$this

attachments() ¶ public

attachments(string|array|null $attachments = null): array|$this

Add attachments to the email message

Attachments can be defined in a few forms depending on how much control you need:

Attach a single file:

$email->attachments('path/to/file');

Attach a file with a different filename:

$email->attachments(['custom_name.txt' => 'path/to/file.txt']);

Attach a file and specify additional properties:

$email->attachments(['custom_name.png' => [
     'file' => 'path/to/file',
     'mimetype' => 'image/png',
     'contentId' => 'abc123',
     'contentDisposition' => false
   ]
]);

Attach a file from string and specify additional properties:

$email->attachments(['custom_name.png' => [
     'data' => file_get_contents('path/to/file'),
     'mimetype' => 'image/png'
   ]
]);

The contentId key allows you to specify an inline attachment. In your email text, you can use <img src="cid:abc123" /> to display the image inline.

The contentDisposition key allows you to disable the Content-Disposition header, this can improve attachment compatibility with outlook email clients.

Parameters
string|array|null $attachments optional

String with the filename or array with filenames

Returns
array|$this
Throws
InvalidArgumentException

bcc() ¶ public

bcc(string|array|null $email = null, string|null $name = null): array|$this

Bcc

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this

cc() ¶ public

cc(string|array|null $email = null, string|null $name = null): array|$this

Cc

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this

charset() ¶ public

charset(string|null $charset = null): string

Charset setter/getter

Parameters
string|null $charset optional

Character set.

Returns
string

config() ¶ public static

config(string|array $key, array|null $config = null): array|null

This method can be used to define configuration adapters for an application or read existing configuration.

To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.

Adapters will not be constructed until the first operation is done.

Usage

Assuming that the class' name is Cache the following scenarios are supported:

Reading config data back:

Cache::config('default');

Setting a cache engine up.

Cache::config('default', $settings);

Injecting a constructed adapter in:

Cache::config('default', $instance);

Configure multiple adapters at once:

Cache::config($arrayOfConfig);
Parameters
string|array $key

The name of the configuration, or an array of multiple configs.

array|null $config optional

An array of name => configuration data for adapter.

Returns
array|null
Throws
BadMethodCallException
When trying to modify an existing config.

configTransport() ¶ public static

configTransport(string|array $key, array|Cake\Mailer\AbstractTransport|null $config = null): array|null

Add or read transport configuration.

Use this method to define transports to use in delivery profiles. Once defined you cannot edit the configurations, and must use Email::dropTransport() to flush the configuration first.

When using an array of configuration data a new transport will be constructed for each message sent. When using a Closure, the closure will be evaluated for each message.

The className is used to define the class to use for a transport. It can either be a short name, or a fully qualified classname

Parameters
string|array $key

The configuration name to read/write. Or an array of multiple transports to set.

array|Cake\Mailer\AbstractTransport|null $config optional

Either an array of configuration data, or a transport instance.

Returns
array|null
Throws
BadMethodCallException
When modifying an existing configuration.

configured() ¶ public static

configured(): array

Returns an array containing the named configurations

Returns
array

configuredTransport() ¶ public static

configuredTransport(): array

Returns an array containing the named transport configurations

Returns
array

createFromArray() ¶ public

createFromArray(array $config): Cake\Mailer\Email

Configures an email instance object from serialized config.

Parameters
array $config

Email configuration array.

Returns
Cake\Mailer\Email

createView() ¶ public

createView(string|null $viewClass = null): Cake\View\View

Constructs the view class instance based on the current configuration.

Parameters
string|null $viewClass optional

Optional namespaced class name of the View class to instantiate.

Returns
Cake\View\View
Throws
Cake\View\Exception\MissingViewException
If view class was not found.

deliver() ¶ public static

deliver(string|array|null $to = null, string|null $subject = null, string|array|null $message = null, string|array $transportConfig = 'fast', bool $send = true): Cake\Mailer\Email

Static method to fast create an instance of \Cake\Mailer\Email

Parameters
string|array|null $to optional

Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config

string|null $subject optional

String of subject or null to use 'subject' from transport config

string|array|null $message optional

String with message or array with variables to be used in render

string|array $transportConfig optional

String to use config from EmailConfig or array with configs

bool $send optional

Send the email or just return the instance pre-configured

Returns
Cake\Mailer\Email
Throws
InvalidArgumentException

domain() ¶ public

domain(string|null $domain = null): string|$this

Domain as top level (the part after @)

Parameters
string|null $domain optional

Manually set the domain for CLI mailing

Returns
string|$this

drop() ¶ public static

drop(string $config): bool

Drops a constructed adapter.

If you wish to modify an existing configuration, you should drop it, change configuration and then re-add it.

If the implementing objects supports a $_registry object the named configuration will also be unloaded from the registry.

Parameters
string $config

An existing configuration you wish to remove.

Returns
bool

dropTransport() ¶ public static

dropTransport(string $key): void

Delete transport configuration.

Parameters
string $key

The transport name to remove.

Returns
void

dsnClassMap() ¶ public static

dsnClassMap(array|null $map = null): array

Returns or updates the DSN class map for this class

Parameters
array|null $map optional

Additions/edits to the class map to apply

Returns
array

emailFormat() ¶ public

emailFormat(string|null $format = null): string|$this

Email format

Parameters
string|null $format optional

Formatting string.

Returns
string|$this
Throws
InvalidArgumentException

emailPattern() ¶ public

emailPattern(string|bool|null $regex = false): string|$this

EmailPattern setter/getter

Parameters
string|bool|null $regex optional

The pattern to use for email address validation, null to unset the pattern and make use of filter_var() instead, false or nothing to return the current value

Returns
string|$this

from() ¶ public

from(string|array|null $email = null, string|null $name = null): array|$this

From

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this
Throws
InvalidArgumentException

getHeaders() ¶ public

getHeaders(array $include = []): array

Get list of headers

Includes:

  • from
  • replyTo
  • readReceipt
  • returnPath
  • to
  • cc
  • bcc
  • subject
Parameters
array $include optional

List of headers.

Returns
array

headerCharset() ¶ public

headerCharset(string|null $charset = null): string

HeaderCharset setter/getter

Parameters
string|null $charset optional

Character set.

Returns
string

helpers() ¶ public

helpers(array|null $helpers = null): array|$this

Helpers to be used in render

Parameters
array|null $helpers optional

Helpers list.

Returns
array|$this

jsonSerialize() ¶ public

jsonSerialize(): array

Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.

It has certain limitations for viewVars that are good to know:

  • ORM\Query executed and stored as resultset
    • SimpleXmlElements stored as associative array
    • Exceptions stored as strings
    • Resources, \Closure and \PDO are not supported.
Returns
array
Throws
Exception
When a view var object can not be properly serialized.

message() ¶ public

message(string|null $type = null): string|array

Get generated message (used by transport classes)

Parameters
string|null $type optional

Use MESSAGE_* constants or null to return the full message as array

Returns
string|array

messageId() ¶ public

messageId(bool|string|null $message = null): bool|string|$this

Message-ID

Parameters
bool|string|null $message optional

True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID

Returns
bool|string|$this
Throws
InvalidArgumentException

parseDsn() ¶ public static

parseDsn(string $dsn): array

Parses a DSN into a valid connection configuration

This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:

$dsn = 'mysql://user:pass@localhost/database?';
$config = ConnectionManager::parseDsn($dsn);

$dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS';
$config = Log::parseDsn($dsn);

$dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null';
$config = Email::parseDsn($dsn);

$dsn = 'file:///?className=\My\Cache\Engine\FileEngine';
$config = Cache::parseDsn($dsn);

$dsn = 'File://?prefix=myapp_cake_core_&serialize=true&duration=+2 minutes&path=/tmp/persistent/';
$config = Cache::parseDsn($dsn);

For all classes, the value of scheme is set as the value of both the className unless they have been otherwise specified.

Note that querystring arguments are also parsed and set as values in the returned configuration.

Parameters
string $dsn

The DSN string to convert to a configuration array

Returns
array
Throws
InvalidArgumentException
If not passed a string

profile() ¶ public

profile(null|string|array $config = null): string|array|$this

Get/Set the configuration profile to use for this instance.

Parameters
null|string|array $config optional

String with configuration name, or an array with config or null to return current config.

Returns
string|array|$this

readReceipt() ¶ public

readReceipt(string|array|null $email = null, string|null $name = null): array|$this

Read Receipt (Disposition-Notification-To header)

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this
Throws
InvalidArgumentException

replyTo() ¶ public

replyTo(string|array|null $email = null, string|null $name = null): array|$this

Reply-To

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this
Throws
InvalidArgumentException

reset() ¶ public

reset(): $this

Reset all the internal variables to be able to send out a new email.

Returns
$this

returnPath() ¶ public

returnPath(string|array|null $email = null, string|null $name = null): array|$this

Return Path

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this
Throws
InvalidArgumentException

send() ¶ public

send(string|array|null $content = null): array

Send an email using the specified content, template and layout

Parameters
string|array|null $content optional

String with message or array with messages

Returns
array
Throws
BadMethodCallException

sender() ¶ public

sender(string|array|null $email = null, string|null $name = null): array|$this

Sender

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this
Throws
InvalidArgumentException

serialize() ¶ public

serialize(): string

Serializes the Email object.

Returns
string

set() ¶ public

set(string|array $name, string|array|null|bool $value = null): $this

Saves a variable or an associative array of variables for use inside a template.

Parameters
string|array $name

A string or an array of data.

string|array|null|bool $value optional

Value in case $name is a string (which then works as the key). Unused if $name is an associative array, otherwise serves as the values to $name's keys.

Returns
$this

setHeaders() ¶ public

setHeaders(array $headers): $this

Sets headers for the message

Parameters
array $headers

Associative array containing headers to be set.

Returns
$this

subject() ¶ public

subject(string|null $subject = null): string|$this

Get/Set Subject.

Parameters
string|null $subject optional

Subject string.

Returns
string|$this

template() ¶ public

template(bool|string $template = false, bool|string $layout = false): array|$this

Template and layout

Parameters
bool|string $template optional

Template name or null to not use

bool|string $layout optional

Layout name or null to not use

Returns
array|$this

theme() ¶ public

theme(string|null $theme = null): string|$this

Theme to use when rendering

Parameters
string|null $theme optional

Theme name.

Returns
string|$this

to() ¶ public

to(string|array|null $email = null, string|null $name = null): array|$this

To

Parameters
string|array|null $email optional

Null to get, String with email, Array with email as key, name as value or email as value (without name)

string|null $name optional

Name

Returns
array|$this

transport() ¶ public

transport(string|Cake\Mailer\AbstractTransport|null $name = null): Cake\Mailer\AbstractTransport|$this

Get/set the transport.

When setting the transport you can either use the name of a configured transport or supply a constructed transport.

Parameters
string|Cake\Mailer\AbstractTransport|null $name optional

Either the name of a configured transport, or a transport instance.

Returns
Cake\Mailer\AbstractTransport|$this
Throws
LogicException
When the chosen transport lacks a send method.
InvalidArgumentException
When $name is neither a string nor an object.

unserialize() ¶ public

unserialize(string $data): Cake\Mailer\Email

Unserializes the Email object.

Parameters
string $data

Serialized string.

Returns
Cake\Mailer\Email

viewBuilder() ¶ public

viewBuilder(): Cake\View\ViewBuilder

Get the view builder being used.

Returns
Cake\View\ViewBuilder

viewOptions() ¶ public

viewOptions(string|array|null $options = null, bool $merge = true): array

Get/Set valid view options in the object's _validViewOptions property. The property is created as an empty array if it is not set. If called without any parameters it will return the current list of valid view options. See createView().

Parameters
string|array|null $options optional

string or array of string to be appended to _validViewOptions.

bool $merge optional

Whether to merge with or override existing valid View options. Defaults to true.

Returns
array

viewRender() ¶ public

viewRender(string|null $viewClass = null): string|$this

View class for render

Parameters
string|null $viewClass optional

View class name.

Returns
string|$this

viewVars() ¶ public

viewVars(array|null $viewVars = null): array|$this

Variables to be set on render

Parameters
array|null $viewVars optional

Variables to set for view.

Returns
array|$this

Property Detail

$_appCharset ¶ protected

The application wide charset, used to encode headers and body

Type
string

$_attachments ¶ protected

List of files that should be attached to the email.

Only absolute paths

Type
array

$_bcc ¶ protected

Blind Carbon Copy

List of email's that should receive a copy of the email. The Recipient WILL NOT be able to see this list

Type
array

$_boundary ¶ protected

If set, boundary to use for multipart mime messages

Type
string

$_cc ¶ protected

Carbon Copy

List of email's that should receive a copy of the email. The Recipient WILL be able to see this list

Type
array

$_charset8bit ¶ protected

8Bit character sets

Type
array

$_config ¶ protected static

Configuration sets.

Type
array

$_contentTypeCharset ¶ protected

Define Content-Type charset name

Type
array

$_domain ¶ protected

Domain for messageId generation. Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty

Type
string

$_dsnClassMap ¶ protected static

An array mapping url schemes to fully qualified Transport class names

Type
array

$_emailFormat ¶ protected

What format should the email be sent in

Type
string

$_emailFormatAvailable ¶ protected

Available formats to be sent.

Type
array

$_emailPattern ¶ protected

Regex for email validation

If null, filter_var() will be used. Use the emailPattern() method to set a custom pattern.'

Type
string

$_from ¶ protected

The mail which the email is sent from

Type
array

$_headers ¶ protected

Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5

Type
array

$_htmlMessage ¶ protected

Html message

Type
string

$_message ¶ protected

Final message to send

Type
array

$_messageId ¶ protected

Message ID

Type
bool|string

$_profile ¶ protected

A copy of the configuration profile for this instance. This copy can be modified with Email::profile().

Type
array

$_readReceipt ¶ protected

The read receipt email

Type
array

$_replyTo ¶ protected

The email the recipient will reply to

Type
array

$_returnPath ¶ protected

The mail that will be used in case of any errors like

  • Remote mailserver down
  • Remote user has exceeded his quota
  • Unknown user
Type
array

$_sender ¶ protected

The sender email

Type
array

$_subject ¶ protected

The subject of the email

Type
string

$_textMessage ¶ protected

Text message

Type
string

$_to ¶ protected

Recipient of the email

Type
array

$_transport ¶ protected

The transport instance to use for sending mail.

Type
Cake\Mailer\AbstractTransport

$_transportConfig ¶ protected static

Configuration profiles for transports.

Type
array

$_viewBuilder ¶ protected

The view builder instance being used.

Type
Cake\View\ViewBuilder

$charset ¶ public

Charset the email body is sent in

Type
string

$headerCharset ¶ public

Charset the email header is sent in If null, the $charset property will be used as default

Type
string

$viewClass ¶ public deprecated

The name of default View class.

Type
string

$viewVars ¶ public

Variables for the view

Type
array
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs