Class Email
CakePHP Email class.
This class is used for sending Internet Message Format based on the standard outlined in https://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.
Constants
- 
          
          stringEMAIL_PATTERN ¶'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui'Holds the regex pattern for email validation 
- 
          
          intLINE_LENGTH_MUST ¶998Line length - no must more - RFC 2822 - 2.1.1 
- 
          
          intLINE_LENGTH_SHOULD ¶78Line length - no should more - RFC 2822 - 2.1.1 
- 
          
          stringMESSAGE_HTML ¶'html'Type of message - HTML 
- 
          
          stringMESSAGE_TEXT ¶'text'Type of message - TEXT 
Property Summary
- 
        $_appCharset protectedstring|nullThe application wide charset, used to encode headers and body 
- 
        $_attachments protectedarrayList of files that should be attached to the email. 
- 
        $_bcc protectedarrayBlind Carbon Copy 
- 
        $_boundary protectedstring|nullIf set, boundary to use for multipart mime messages 
- 
        $_cc protectedarrayCarbon Copy 
- 
        $_charset8bit protectedarray8Bit character sets 
- 
        $_config protected staticarrayConfiguration sets. 
- 
        $_contentTypeCharset protectedarrayDefine Content-Type charset name 
- 
        $_domain protectedstringDomain for messageId generation. Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty 
- 
        $_dsnClassMap protected static deprecatedstring[]An array mapping url schemes to fully qualified Transport class names. Unused. 
- 
        $_emailFormat protectedstringWhat format should the email be sent in 
- 
        $_emailFormatAvailable protectedarrayAvailable formats to be sent. 
- 
        $_emailPattern protectedstringRegex for email validation 
- 
        $_from protectedarrayThe mail which the email is sent from 
- 
        $_headers protectedarrayAssociative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5 
- 
        $_htmlMessage protectedstringHtml message 
- 
        $_message protectedarrayFinal message to send 
- 
        $_messageId protectedbool|stringMessage ID 
- 
        $_priority protectedint|nullContains the optional priority of the email. 
- 
        $_profile protectedarrayA copy of the configuration profile for this instance. This copy can be modified with Email::profile(). 
- 
        $_readReceipt protectedarrayThe read receipt email 
- 
        $_replyTo protectedarrayList of email(s) that the recipient will reply to. 
- 
        $_returnPath protectedarrayThe mail that will be used in case of any errors like - Remote mailserver down
- Remote user has exceeded his quota
- Unknown user
 
- 
        $_sender protectedarrayThe sender email 
- 
        $_subject protectedstringThe subject of the email 
- 
        $_textMessage protectedstringText message 
- 
        $_to protectedarrayRecipient of the email 
- 
        $_transferEncodingAvailable protectedarrayAvailable encoding to be set for transfer. 
- 
        $_transport protectedCake\Mailer\AbstractTransport|nullThe transport instance to use for sending mail. 
- 
        $_validViewOptions public @propertyarray
- 
        $_viewBuilder protectedCake\View\ViewBuilderThe view builder instance being used. 
- 
        $charset publicstringCharset the email body is sent in 
- 
        $headerCharset publicstring|nullCharset the email header is sent in If null, the $charset property will be used as default 
- 
        $transferEncoding protectedstring|nullThe email transfer encoding used. If null, the $charset property is used for determined the transfer encoding. 
- 
        $viewClass public deprecatedstring|nullThe name of default View class. 
- 
        $viewVars publicarrayVariables for the view. 
Method Summary
- 
          __clone() publicClone ViewBuilder instance when email object is cloned. 
- 
          __construct() publicConstructor 
- 
          _addEmail() protectedAdd email 
- 
          _applyConfig() protectedApply the config to an instance 
- 
          _attachFiles() protectedAttach non-embedded files by adding file contents inside boundaries. 
- 
          _attachInlineFiles() protectedAttach inline/embedded files to the message. 
- 
          _checkViewVars() protectedIterates through hash to clean up and normalize. 
- 
          _createBoundary() protectedCreate unique boundary identifier 
- 
          _decode() protectedDecode the specified string 
- 
          _encode() protectedEncode the specified string using the current charset 
- 
          _encodeString() protectedTranslates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists 
- 
          _formatAddress() protectedFormat addresses 
- 
          _getContentTransferEncoding() protectedReturn the Content-Transfer Encoding value based on the set transferEncoding or set charset. 
- 
          _getContentTypeCharset() protectedReturn charset value for Content-Type. 
- 
          _getTypes() protectedGets the text body types that are in this email message 
- 
          _logDelivery() protectedLog the email message delivery. 
- 
          _readFile() protectedRead the file contents and return a base64 version of the file contents. 
- 
          _render() protectedRender the body of the email. 
- 
          _renderTemplates() protectedBuild 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() protectedSet email 
- 
          _setEmailSingle() protectedSet only 1 email 
- 
          _validateEmail() protectedValidate email address 
- 
          _wrap() protectedWrap the message to follow the RFC 2822 - 2.1.1 
- 
          addAttachments() publicAdd attachments 
- 
          addBcc() publicAdd Bcc 
- 
          addCc() publicAdd Cc 
- 
          addHeaders() publicAdd header for the message 
- 
          addTo() publicAdd To 
- 
          attachments() public deprecatedAdd attachments to the email message 
- 
          bcc() public deprecatedBcc 
- 
          cc() public deprecatedCc 
- 
          charset() public deprecatedCharset setter/getter 
- 
          config() public static deprecatedThis method can be used to define configuration adapters for an application or read existing configuration. 
- 
          configTransport() public static deprecatedAdd or read transport configuration. 
- 
          configured() public staticReturns an array containing the named configurations 
- 
          configuredTransport() public static deprecatedReturns an array containing the named transport configurations 
- 
          createFromArray() publicConfigures an email instance object from serialized config. 
- 
          createView() publicConstructs the view class instance based on the current configuration. 
- 
          deliver() public staticStatic method to fast create an instance of \Cake\Mailer\Email 
- 
          domain() public deprecatedDomain as top level (the part after @) 
- 
          drop() public staticDrops a constructed adapter. 
- 
          dropTransport() public static deprecatedDelete transport configuration. 
- 
          dsnClassMap() public static deprecatedReturns or updates the DSN class map for this class. 
- 
          emailFormat() public deprecatedEmail format 
- 
          emailPattern() public deprecatedEmailPattern setter/getter 
- 
          flatten() protectedConverts given value to string 
- 
          from() public deprecatedFrom 
- 
          getAttachments() publicGets attachments to the email message. 
- 
          getBcc() publicGets "bcc" address. 
- 
          getCc() publicGets "cc" address. 
- 
          getCharset() publicCharset getter. 
- 
          getConfig() public staticReads existing configuration. 
- 
          getConfigOrFail() public staticReads existing configuration for a specific key. 
- 
          getConfigTransport() public static deprecatedGets current transport configuration. 
- 
          getDomain() publicGets domain. 
- 
          getDsnClassMap() public staticReturns the DSN class map for this class. 
- 
          getEmailFormat() publicGets email format. 
- 
          getEmailPattern() publicEmailPattern setter/getter 
- 
          getFrom() publicGets "from" address. 
- 
          getHeaderCharset() publicHeaderCharset getter. 
- 
          getHeaders() publicGet list of headers 
- 
          getHelpers() public deprecatedGets helpers to be used when rendering. 
- 
          getLayout() public deprecatedGets layout. 
- 
          getMessageId() publicGets message ID. 
- 
          getOriginalSubject() publicGet original subject without encoding 
- 
          getPriority() publicGets priority. 
- 
          getProfile() publicGets the configuration profile to use for this instance. 
- 
          getReadReceipt() publicGets Read Receipt (Disposition-Notification-To header). 
- 
          getReplyTo() publicGets "Reply-To" address. 
- 
          getReturnPath() publicGets return path. 
- 
          getSender() publicGets the "sender" address. See rfc link below for full explanation. 
- 
          getSubject() publicGets subject. 
- 
          getTemplate() public deprecatedGets template. 
- 
          getTheme() public deprecatedGets theme to use when rendering. 
- 
          getTo() publicGets "to" address 
- 
          getTransferEncoding() publicTransferEncoding getter. 
- 
          getTransport() publicGets the transport. 
- 
          getViewRenderer() publicGets view class for render. 
- 
          getViewVars() publicGets variables to be set on render. 
- 
          headerCharset() public deprecatedHeaderCharset setter/getter 
- 
          helpers() public deprecatedHelpers to be used in render 
- 
          jsonSerialize() publicSerializes the email object to a value that can be natively serialized and re-used to clone this email instance. 
- 
          message() publicGet generated message (used by transport classes) 
- 
          messageId() public deprecatedMessage-ID 
- 
          parseDsn() public staticParses a DSN into a valid connection configuration 
- 
          profile() public deprecatedGet/Set the configuration profile to use for this instance. 
- 
          readReceipt() public deprecatedRead Receipt (Disposition-Notification-To header) 
- 
          replyTo() public deprecatedReply-To 
- 
          reset() publicReset all the internal variables to be able to send out a new email. 
- 
          returnPath() public deprecatedReturn Path 
- 
          send() publicSend an email using the specified content, template and layout 
- 
          sender() public deprecatedSender 
- 
          serialize() publicSerializes the Email object. 
- 
          set() publicSaves a variable or an associative array of variables for use inside a template. 
- 
          setAttachments() publicAdd attachments to the email message 
- 
          setBcc() publicSets "bcc" address. 
- 
          setCc() publicSets "cc" address. 
- 
          setCharset() publicCharset setter. 
- 
          setConfig() public staticThis method can be used to define configuration adapters for an application. 
- 
          setConfigTransport() public static deprecatedSets transport configuration. 
- 
          setDomain() publicSets domain. 
- 
          setDsnClassMap() public staticUpdates the DSN class map for this class. 
- 
          setEmailFormat() publicSets email format. 
- 
          setEmailPattern() publicEmailPattern setter/getter 
- 
          setFrom() publicSets "from" address. 
- 
          setHeaderCharset() publicHeaderCharset setter. 
- 
          setHeaders() publicSets headers for the message 
- 
          setHelpers() public deprecatedSets helpers to be used when rendering. 
- 
          setLayout() public deprecatedSets layout. 
- 
          setMessageId() publicSets message ID. 
- 
          setPriority() publicSets priority. 
- 
          setProfile() publicSets the configuration profile to use for this instance. 
- 
          setReadReceipt() publicSets Read Receipt (Disposition-Notification-To header). 
- 
          setReplyTo() publicSets "Reply-To" address. 
- 
          setReturnPath() publicReturn Path 
- 
          setSender() publicSets the "sender" address. See rfc link below for full explanation. 
- 
          setSubject() publicSets subject. 
- 
          setTemplate() public deprecatedSets template. 
- 
          setTheme() public deprecatedSets theme to use when rendering. 
- 
          setTo() publicSets "to" address. 
- 
          setTransferEncoding() publicTransferEncoding setter. 
- 
          setTransport() publicSets the transport. 
- 
          setViewRenderer() publicSets view class for render. 
- 
          setViewVars() publicSets variables to be set on render. 
- 
          subject() public deprecatedGet/Set Subject. 
- 
          template() public deprecatedTemplate and layout 
- 
          theme() public deprecatedTheme to use when rendering 
- 
          to() public deprecatedTo 
- 
          transport() public deprecatedGet/set the transport. 
- 
          unserialize() publicUnserializes the Email object. 
- 
          viewBuilder() publicGet the view builder being used. 
- 
          viewOptions() public deprecatedGet/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 deprecatedView class for render 
- 
          viewVars() public deprecatedVariables to be set on render 
Method Detail
__clone() ¶ public
__clone(): voidClone 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 app.php 
_addEmail() ¶ protected
_addEmail(string $varName, string|array $email, string $name): $thisAdd 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
$thisThrows
InvalidArgumentException_applyConfig() ¶ protected
_applyConfig(string|array $config): voidApply the config to an instance
Parameters
- 
                string|array$config
- Configuration options. 
Returns
voidThrows
InvalidArgumentExceptionWhen using a configuration that doesn't exist.
_attachFiles() ¶ protected
_attachFiles(string|null $boundary = null): arrayAttach 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
arrayAn array of lines to add to the message
_attachInlineFiles() ¶ protected
_attachInlineFiles(string|null $boundary = null): arrayAttach inline/embedded files to the message.
Parameters
- 
                string|null$boundary optional
- Boundary to use. If null, will default to $this->_boundary 
Returns
arrayAn array of lines to add to the message
_checkViewVars() ¶ protected
_checkViewVars(mixed $item, string $key): voidIterates through hash to clean up and normalize.
Parameters
- 
                mixed$item
- Reference to the view var value. 
- 
                string$key
- View var key. 
Returns
void_createBoundary() ¶ protected
_createBoundary(): voidCreate unique boundary identifier
Returns
void_decode() ¶ protected
_decode(string $text): stringDecode the specified string
Parameters
- 
                string$text
- String to decode 
Returns
stringDecoded string
_encode() ¶ protected
_encode(string $text): stringEncode the specified string using the current charset
Parameters
- 
                string$text
- String to encode 
Returns
stringEncoded string
_encodeString() ¶ protected
_encodeString(string $text, string $charset): stringTranslates 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): arrayFormat 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(): stringReturn the Content-Transfer Encoding value based on the set transferEncoding or set charset.
Returns
string_getContentTypeCharset() ¶ protected
_getContentTypeCharset(): stringReturn charset value for Content-Type.
Checks fallback/compatibility types which include workarounds for legacy japanese character sets.
Returns
string_getTypes() ¶ protected
_getTypes(): arrayGets the text body types that are in this email message
Returns
arrayArray of types. Valid types are 'text' and 'html'
_logDelivery() ¶ protected
_logDelivery(array $contents): voidLog the email message delivery.
Parameters
- 
                array$contents
- The content with 'headers' and 'message' keys. 
Returns
void_readFile() ¶ protected
_readFile(string $path): stringRead the file contents and return a base64 version of the file contents.
Parameters
- 
                string$path
- The absolute path to the file to read. 
Returns
stringFile contents in base64 encoding
_render() ¶ protected
_render(array $content): arrayRender the body of the email.
Parameters
- 
                array$content
- Content to render 
Returns
arrayEmail body ready to be sent
_renderTemplates() ¶ protected
_renderTemplates(string $content): arrayBuild 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
arrayThe rendered content with html and text keys.
_setEmail() ¶ protected
_setEmail(string $varName, string|array $email, string $name): $thisSet 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
$thisThrows
InvalidArgumentException_setEmailSingle() ¶ protected
_setEmailSingle(string $varName, string|array $email, string $name, string $throwMessage): $thisSet 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
$thisThrows
InvalidArgumentException_validateEmail() ¶ protected
_validateEmail(string $email, string $context): voidValidate email address
Parameters
- 
                string$email
- Email address to validate 
- 
                string$context
- Which property was set 
Returns
voidThrows
InvalidArgumentExceptionIf email address does not validate
_wrap() ¶ protected
_wrap(string $message, int $wrapLength = Email::LINE_LENGTH_MUST): arrayWrap the message to follow the RFC 2822 - 2.1.1
Parameters
- 
                string$message
- Message to wrap 
- 
                int$wrapLength optional
- The line length 
Returns
arrayWrapped message
addAttachments() ¶ public
addAttachments(string|array $attachments): $thisAdd attachments
Parameters
- 
                string|array$attachments
- String with the filename or array with filenames 
Returns
$thisThrows
InvalidArgumentExceptionSee Also
addBcc() ¶ public
addBcc(string|array $email, string|null $name = null): $thisAdd 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
$thisaddCc() ¶ public
addCc(string|array $email, string|null $name = null): $thisAdd 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
$thisaddHeaders() ¶ public
addHeaders(array $headers): $thisAdd header for the message
Parameters
- 
                array$headers
- Headers to set. 
Returns
$thisaddTo() ¶ public
addTo(string|array $email, string|null $name = null): $thisAdd 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
$thisattachments() ¶ public
attachments(string|array|null $attachments = null): array|$thisAdd 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->setAttachments('path/to/file');Attach a file with a different filename:
$email->setAttachments(['custom_name.txt' => 'path/to/file.txt']);Attach a file and specify additional properties:
$email->setAttachments(['custom_name.png' => [
     'file' => 'path/to/file',
     'mimetype' => 'image/png',
     'contentId' => 'abc123',
     'contentDisposition' => false
   ]
]);Attach a file from string and specify additional properties:
$email->setAttachments(['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|$thisEither the array of attachments when getting or $this when setting.
Throws
InvalidArgumentExceptionbcc() ¶ public
bcc(string|array|null $email = null, string|null $name = null): array|$thisBcc
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|$thiscc() ¶ public
cc(string|array|null $email = null, string|null $name = null): array|$thisCc
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|$thischarset() ¶ public
charset(string|null $charset = null): stringCharset setter/getter
Parameters
- 
                string|null$charset optional
- Character set. 
Returns
stringCharset
config() ¶ public static
config(string|array $key, array|null $config = null): array|nullThis 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|nullNull when adding configuration or an array of configuration data when reading.
Throws
BadMethodCallExceptionWhen trying to modify an existing config.
configTransport() ¶ public static
configTransport(string|array $key, array|Cake\Mailer\AbstractTransport|null $config = null): array|nullAdd 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|nullEither null when setting or an array of data when reading.
Throws
BadMethodCallExceptionWhen modifying an existing configuration.
configured() ¶ public static
configured(): string[]Returns an array containing the named configurations
Returns
string[]Array of configurations.
configuredTransport() ¶ public static
configuredTransport(): arrayReturns an array containing the named transport configurations
Returns
arrayArray of configurations.
createFromArray() ¶ public
createFromArray(array $config): $thisConfigures an email instance object from serialized config.
Parameters
- 
                array$config
- Email configuration array. 
Returns
$thisConfigured email instance.
createView() ¶ public
createView(string|null $viewClass = null): Cake\View\ViewConstructs 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\ViewThrows
Cake\View\Exception\MissingViewExceptionIf 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 $config = 'default', bool $send = true): staticStatic 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$config optional
- String to use Email delivery profile from app.php or array with configs 
- 
                bool$send optional
- Send the email or just return the instance pre-configured 
Returns
staticInstance of Cake\Mailer\Email
Throws
InvalidArgumentExceptiondomain() ¶ public
domain(string|null $domain = null): string|$thisDomain as top level (the part after @)
Parameters
- 
                string|null$domain optional
- Manually set the domain for CLI mailing 
Returns
string|$thisdrop() ¶ public static
drop(string $config): boolDrops 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
boolSuccess of the removal, returns false when the config does not exist.
dropTransport() ¶ public static
dropTransport(string $key): voidDelete transport configuration.
Parameters
- 
                string$key
- The transport name to remove. 
Returns
voiddsnClassMap() ¶ public static
dsnClassMap(string[]|null $map = null): string[]Returns or updates the DSN class map for this class.
Parameters
- 
                string[]|null$map optional
- Additions/edits to the class map to apply. 
Returns
string[]emailFormat() ¶ public
emailFormat(string|null $format = null): string|$thisEmail format
Parameters
- 
                string|null$format optional
- Formatting string. 
Returns
string|$thisThrows
InvalidArgumentExceptionemailPattern() ¶ public
emailPattern(string|false|null $regex = false): string|$thisEmailPattern setter/getter
Parameters
- 
                string|false|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|$thisflatten() ¶ protected
flatten(string|array $value): stringConverts given value to string
Parameters
- 
                string|array$value
- The value to convert 
Returns
stringfrom() ¶ public
from(string|array|null $email = null, string|null $name = null): array|$thisFrom
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|$thisThrows
InvalidArgumentExceptiongetAttachments() ¶ public
getAttachments(): arrayGets attachments to the email message.
Returns
arrayArray of attachments.
getConfig() ¶ public static
getConfig(string $key): mixed|nullReads existing configuration.
Parameters
- 
                string$key
- The name of the configuration. 
Returns
mixed|nullConfiguration data at the named key or null if the key does not exist.
getConfigOrFail() ¶ public static
getConfigOrFail(string|null $key): mixedReads existing configuration for a specific key.
The config value for this key must exist, it can never be null.
Parameters
- 
                string|null$key
- The name of the configuration. 
Returns
mixedConfiguration data at the named key.
Throws
InvalidArgumentExceptionIf value does not exist.
getConfigTransport() ¶ public static
getConfigTransport(string $key): array|nullGets current transport configuration.
Parameters
- 
                string$key
- The configuration name to read. 
Returns
array|nullTransport config.
getDsnClassMap() ¶ public static
getDsnClassMap(): string[]Returns the DSN class map for this class.
Returns
string[]getHeaders() ¶ public
getHeaders(array $include = []): arrayGet list of headers
Includes:
- from
- replyTo
- readReceipt
- returnPath
- to
- cc
- bcc
- subject
Parameters
- 
                array$include optional
- List of headers. 
Returns
arraygetOriginalSubject() ¶ public
getOriginalSubject(): stringGet original subject without encoding
Returns
stringOriginal subject
getProfile() ¶ public
getProfile(): string|arrayGets the configuration profile to use for this instance.
Returns
string|arraygetReadReceipt() ¶ public
getReadReceipt(): arrayGets Read Receipt (Disposition-Notification-To header).
Returns
arraygetSender() ¶ public
getSender(): arrayGets the "sender" address. See rfc link below for full explanation.
Returns
arrayLinks
getTransferEncoding() ¶ public
getTransferEncoding(): string|nullTransferEncoding getter.
Returns
string|nullEncoding
getTransport() ¶ public
getTransport(): Cake\Mailer\AbstractTransportGets the transport.
Returns
Cake\Mailer\AbstractTransportheaderCharset() ¶ public
headerCharset(string|null $charset = null): stringHeaderCharset setter/getter
Parameters
- 
                string|null$charset optional
- Character set. 
Returns
stringCharset
helpers() ¶ public
helpers(array|null $helpers = null): array|$thisHelpers to be used in render
Parameters
- 
                array|null$helpers optional
- Helpers list. 
Returns
array|$thisjsonSerialize() ¶ public
jsonSerialize(): arraySerializes 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
arraySerializable array of configuration properties.
Throws
ExceptionWhen a view var object can not be properly serialized.
message() ¶ public
message(string|null $type = null): string|arrayGet 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|arrayString if type is given, array if type is null
messageId() ¶ public
messageId(bool|string|null $message = null): bool|string|$thisMessage-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|$thisThrows
InvalidArgumentExceptionparseDsn() ¶ public static
parseDsn(string $dsn): arrayParses 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
arrayThe configuration array to be stored after parsing the DSN
Throws
InvalidArgumentExceptionIf not passed a string, or passed an invalid string
profile() ¶ public
profile(array|string|null $config = null): string|array|$thisGet/Set the configuration profile to use for this instance.
Parameters
- 
                array|string|null$config optional
- String with configuration name, or an array with config or null to return current config. 
Returns
string|array|$thisreadReceipt() ¶ public
readReceipt(string|array|null $email = null, string|null $name = null): array|$thisRead 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|$thisThrows
InvalidArgumentExceptionreplyTo() ¶ public
replyTo(string|array|null $email = null, string|null $name = null): array|$thisReply-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|$thisThrows
InvalidArgumentExceptionreset() ¶ public
reset(): $thisReset all the internal variables to be able to send out a new email.
Returns
$thisreturnPath() ¶ public
returnPath(string|array|null $email = null, string|null $name = null): array|$thisReturn 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|$thisThrows
InvalidArgumentExceptionsend() ¶ public
send(string|array|null $content = null): arraySend an email using the specified content, template and layout
Parameters
- 
                string|array|null$content optional
- String with message or array with messages 
Returns
arrayThrows
BadMethodCallExceptionsender() ¶ public
sender(string|array|null $email = null, string|null $name = null): array|$thisSender
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|$thisThrows
InvalidArgumentExceptionset() ¶ public
set(string|array $name, mixed $value = null): $thisSaves a variable or an associative array of variables for use inside a template.
Parameters
- 
                string|array$name
- A string or an array of data. 
- 
                mixed$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
$thissetAttachments() ¶ public
setAttachments(string|array $attachments): $thisAdd 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->setAttachments('path/to/file');Attach a file with a different filename:
$email->setAttachments(['custom_name.txt' => 'path/to/file.txt']);Attach a file and specify additional properties:
$email->setAttachments(['custom_name.png' => [
     'file' => 'path/to/file',
     'mimetype' => 'image/png',
     'contentId' => 'abc123',
     'contentDisposition' => false
   ]
]);Attach a file from string and specify additional properties:
$email->setAttachments(['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$attachments
- String with the filename or array with filenames 
Returns
$thisThrows
InvalidArgumentExceptionsetBcc() ¶ public
setBcc(string|array $email, string|null $name = null): $thisSets "bcc" address.
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thissetCc() ¶ public
setCc(string|array $email, string|null $name = null): $thisSets "cc" address.
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thissetCharset() ¶ public
setCharset(string|null $charset): $thisCharset setter.
Parameters
- 
                string|null$charset
- Character set. 
Returns
$thissetConfig() ¶ public static
setConfig(string|array $key, array|object|null $config = null): voidThis method can be used to define configuration adapters for an application.
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:
Setting a cache engine up.
Cache::setConfig('default', $settings);Injecting a constructed adapter in:
Cache::setConfig('default', $instance);Configure multiple adapters at once:
Cache::setConfig($arrayOfConfig);Parameters
- 
                string|array$key
- The name of the configuration, or an array of multiple configs. 
- 
                array|object|null$config optional
- An array of name => configuration data for adapter. 
Returns
voidThrows
BadMethodCallExceptionWhen trying to modify an existing config.
LogicExceptionWhen trying to store an invalid structured config array.
setConfigTransport() ¶ public static
setConfigTransport(string|array $key, array|Cake\Mailer\AbstractTransport|null $config = null): voidSets 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 class name
Parameters
- 
                string|array$key
- The configuration name to 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. Null when using key as array. 
Returns
voidsetDomain() ¶ public
setDomain(string $domain): $thisSets domain.
Domain as top level (the part after @).
Parameters
- 
                string$domain
- Manually set the domain for CLI mailing. 
Returns
$thissetDsnClassMap() ¶ public static
setDsnClassMap(string[] $map): voidUpdates the DSN class map for this class.
Parameters
- 
                string[]$map
- Additions/edits to the class map to apply. 
Returns
voidsetEmailFormat() ¶ public
setEmailFormat(string $format): $thisSets email format.
Parameters
- 
                string$format
- Formatting string. 
Returns
$thisThrows
InvalidArgumentExceptionsetEmailPattern() ¶ public
setEmailPattern(string|null $regex): $thisEmailPattern setter/getter
Parameters
- 
                string|null$regex
- The pattern to use for email address validation, null to unset the pattern and make use of filter_var() instead. 
Returns
$thissetFrom() ¶ public
setFrom(string|array $email, string|null $name = null): $thisSets "from" address.
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
$thisThrows
InvalidArgumentExceptionsetHeaderCharset() ¶ public
setHeaderCharset(string|null $charset): $thisHeaderCharset setter.
Parameters
- 
                string|null$charset
- Character set. 
Returns
$thissetHeaders() ¶ public
setHeaders(array $headers): $thisSets headers for the message
Parameters
- 
                array$headers
- Associative array containing headers to be set. 
Returns
$thissetHelpers() ¶ public
setHelpers(array $helpers): $thisSets helpers to be used when rendering.
Parameters
- 
                array$helpers
- Helpers list. 
Returns
$thissetLayout() ¶ public
setLayout(string|null $layout): $thisSets layout.
Parameters
- 
                string|null$layout
- Layout name or null to not use 
Returns
$thissetMessageId() ¶ public
setMessageId(bool|string $message): $thisSets message ID.
Parameters
- 
                bool|string$message
- True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID. 
Returns
$thisThrows
InvalidArgumentExceptionsetPriority() ¶ public
setPriority(int|null $priority): $thisSets priority.
Parameters
- 
                int|null$priority
- 1 (highest) to 5 (lowest) 
Returns
$thissetProfile() ¶ public
setProfile(string|array $config): $thisSets the configuration profile to use for this instance.
Parameters
- 
                string|array$config
- String with configuration name, or an array with config. 
Returns
$thissetReadReceipt() ¶ public
setReadReceipt(string|array $email, string|null $name = null): $thisSets Read Receipt (Disposition-Notification-To header).
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thisThrows
InvalidArgumentExceptionsetReplyTo() ¶ public
setReplyTo(string|array $email, string|null $name = null): $thisSets "Reply-To" address.
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thisThrows
InvalidArgumentExceptionsetReturnPath() ¶ public
setReturnPath(string|array $email, string|null $name = null): $thisReturn Path
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thisThrows
InvalidArgumentExceptionsetSender() ¶ public
setSender(string|array $email, string|null $name = null): $thisSets the "sender" address. See rfc link below for full explanation.
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thisThrows
InvalidArgumentExceptionLinks
setSubject() ¶ public
setSubject(string $subject): $thisSets subject.
Parameters
- 
                string$subject
- Subject string. 
Returns
$thissetTemplate() ¶ public
setTemplate(string|null $template): $thisSets template.
Parameters
- 
                string|null$template
- Template name or null to not use. 
Returns
$thissetTheme() ¶ public
setTheme(string $theme): $thisSets theme to use when rendering.
Parameters
- 
                string$theme
- Theme name. 
Returns
$thissetTo() ¶ public
setTo(string|array $email, string|null $name = null): $thisSets "to" address.
Parameters
- 
                string|array$email
- String with email, Array with email as key, name as value or email as value (without name) 
- 
                string|null$name optional
- Name 
Returns
$thissetTransferEncoding() ¶ public
setTransferEncoding(string|null $encoding): $thisTransferEncoding setter.
Parameters
- 
                string|null$encoding
- Encoding set. 
Returns
$thissetTransport() ¶ public
setTransport(string|Cake\Mailer\AbstractTransport $name): $thisSets 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$name
- Either the name of a configured transport, or a transport instance. 
Returns
$thisThrows
LogicExceptionWhen the chosen transport lacks a send method.
InvalidArgumentExceptionWhen $name is neither a string nor an object.
setViewRenderer() ¶ public
setViewRenderer(string $viewClass): $thisSets view class for render.
Parameters
- 
                string$viewClass
- View class name. 
Returns
$thissetViewVars() ¶ public
setViewVars(array $viewVars): $thisSets variables to be set on render.
Parameters
- 
                array$viewVars
- Variables to set for view. 
Returns
$thissubject() ¶ public
subject(string|null $subject = null): string|$thisGet/Set Subject.
Parameters
- 
                string|null$subject optional
- Subject string. 
Returns
string|$thistemplate() ¶ public
template(bool|string $template = false, bool|string $layout = false): array|$thisTemplate 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|$thistheme() ¶ public
theme(string|null $theme = null): string|$thisTheme to use when rendering
Parameters
- 
                string|null$theme optional
- Theme name. 
Returns
string|$thisto() ¶ public
to(string|array|null $email = null, string|null $name = null): array|$thisTo
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|$thistransport() ¶ public
transport(string|Cake\Mailer\AbstractTransport|null $name = null): Cake\Mailer\AbstractTransport|$thisGet/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|$thisThrows
LogicExceptionWhen the chosen transport lacks a send method.
InvalidArgumentExceptionWhen $name is neither a string nor an object.
unserialize() ¶ public
unserialize(string $data): staticUnserializes the Email object.
Parameters
- 
                string$data
- Serialized string. 
Returns
staticConfigured email instance.
viewBuilder() ¶ public
viewBuilder(): Cake\View\ViewBuilderGet the view builder being used.
Returns
Cake\View\ViewBuilderviewOptions() ¶ public
viewOptions(string|array|null $options = null, bool $merge = true): arrayGet/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
arrayThe updated view options as an array.
viewRender() ¶ public
viewRender(string|null $viewClass = null): string|$thisView class for render
Parameters
- 
                string|null$viewClass optional
- View class name. 
Returns
string|$thisviewVars() ¶ public
viewVars(array|null $viewVars = null): array|$thisVariables to be set on render
Parameters
- 
                array|null$viewVars optional
- Variables to set for view. 
Returns
array|$thisProperty Detail
$_appCharset ¶ protected
The application wide charset, used to encode headers and body
Type
string|null$_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$_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$_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 deprecated
An array mapping url schemes to fully qualified Transport class names. Unused.
Type
string[]$_emailPattern ¶ protected
Regex for email validation
If null, filter_var() will be used. Use the emailPattern() method to set a custom pattern.'
Type
string$_headers ¶ protected
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
Type
array$_profile ¶ protected
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
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$_transport ¶ protected
The transport instance to use for sending mail.
Type
Cake\Mailer\AbstractTransport|null$headerCharset ¶ public
Charset the email header is sent in If null, the $charset property will be used as default
Type
string|null$transferEncoding ¶ protected
The email transfer encoding used. If null, the $charset property is used for determined the transfer encoding.
Type
string|null$viewVars ¶ public
Variables for the view.
Deprecated: This property will be removed in 4.x.
Inside controller context use $this->set() instead, also see $this->viewBuilder()->getVar().
In view context it will be a protected property View::$viewVars.
Type
array