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.
- Cake\Mailer\Email implements JsonSerializable, Serializable uses Cake\Core\StaticConfigTrait , Cake\View\ViewVarsTrait
Constants summary
Properties summary
-
$_appCharset
protectedstring|null
The application wide charset, used to encode headers and body -
$_attachments
protectedarray
List of files that should be attached to the email. -
$_bcc
protectedarray
Blind Carbon Copy -
$_boundary
protectedstring|null
If set, boundary to use for multipart mime messages -
$_cc
protectedarray
Carbon Copy -
$_charset8bit
protectedarray
8Bit character sets -
$_contentTypeCharset
protectedarray
Define Content-Type charset name -
$_domain
protectedstring
Domain for messageId generation. Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty
-
$_dsnClassMap
protected staticarray
An array mapping url schemes to fully qualified Transport class names. Unused.
-
$_emailFormat
protectedstring
What format should the email be sent in -
$_emailFormatAvailable
protectedarray
Available formats to be sent. -
$_emailPattern
protectedstring
Regex for email validation -
$_from
protectedarray
The mail which the email is sent from -
$_headers
protectedarray
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
-
$_htmlMessage
protectedstring
Html message -
$_message
protectedarray
Final message to send -
$_messageId
protectedboolean|string
Message ID -
$_priority
protectedinteger|null
Contains the optional priority of the email. -
$_profile
protectedarray
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
-
$_readReceipt
protectedarray
The read receipt email -
$_replyTo
protectedarray
The email the recipient will reply to -
$_returnPath
protectedarray
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
-
$_sender
protectedarray
The sender email -
$_subject
protectedstring
The subject of the email -
$_textMessage
protectedstring
Text message -
$_to
protectedarray
Recipient of the email -
$_transferEncodingAvailable
protectedarray
Available encoding to be set for transfer. -
$_transport
protectedThe transport instance to use for sending mail. -
$charset
publicstring
Charset the email body is sent in -
$headerCharset
publicstring|null
Charset the email header is sent in If null, the $charset property will be used as default
-
$transferEncoding
protectedstring|null
The email transfer encoding used. If null, the $charset property is used for determined the transfer encoding.
Inherited Magic Properties
Inherited Properties
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. -
_createBoundary() protected
Create unique boundary identifier -
_decode() protected
Decode the specified string -
_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 transferEncoding or 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 -
configTransport() public static
Add or read transport configuration. -
configuredTransport() public static
Returns an array containing the named transport configurations -
createFromArray() public
Configures an email instance object from serialized config. -
deliver() public static
Static method to fast create an instance of \Cake\Mailer\Email -
domain() public
Domain as top level (the part after @) -
dropTransport() public static
Delete transport configuration. -
emailFormat() public
Email format -
emailPattern() public
EmailPattern setter/getter -
flatten() protected
Converts given value to string -
from() public
From -
getAttachments() public
Gets attachments to the email message. -
getBcc() public
Gets "bcc" address. -
getCc() public
Gets "cc" address. -
getCharset() public
Charset getter. -
getConfigTransport() public static
Gets current transport configuration. -
getDomain() public
Gets domain. -
getEmailFormat() public
Gets email format. -
getEmailPattern() public
EmailPattern setter/getter -
getFrom() public
Gets "from" address. -
getHeaderCharset() public
HeaderCharset getter. -
getHeaders() public
Get list of headers -
getHelpers() public
Gets helpers to be used when rendering. -
getLayout() public
Gets layout. -
getMessageId() public
Gets message ID. -
getOriginalSubject() public
Get original subject without encoding -
getPriority() public
Gets priority. -
getProfile() public
Gets the configuration profile to use for this instance. -
getReadReceipt() public
Gets Read Receipt (Disposition-Notification-To header). -
getReplyTo() public
Gets "Reply-To" address. -
getReturnPath() public
Gets return path. -
getSender() public
Gets "sender" address. -
getSubject() public
Gets subject. -
getTemplate() public
Gets template. -
getTheme() public
Gets theme to use when rendering. -
getTo() public
Gets "to" address -
getTransferEncoding() public
TransferEncoding getter. -
getTransport() public
Gets the transport. -
getViewRenderer() public
Gets view class for render. -
getViewVars() public
Gets variables to be set on render. -
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 -
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. -
setAttachments() public
Add attachments to the email message -
setBcc() public
Sets "bcc" address. -
setCc() public
Sets "cc" address. -
setCharset() public
Charset setter. -
setConfigTransport() public static
Sets transport configuration. -
setDomain() public
Sets domain. -
setEmailFormat() public
Sets email format. -
setEmailPattern() public
EmailPattern setter/getter -
setFrom() public
Sets "from" address. -
setHeaderCharset() public
HeaderCharset setter. -
setHeaders() public
Sets headers for the message -
setHelpers() public
Sets helpers to be used when rendering. -
setLayout() public
Sets layout. -
setMessageId() public
Sets message ID. -
setPriority() public
Sets priority. -
setProfile() public
Sets the configuration profile to use for this instance. -
setReadReceipt() public
Sets Read Receipt (Disposition-Notification-To header). -
setReplyTo() public
Sets "Reply-To" address. -
setReturnPath() public
Return Path -
setSender() public
Sets "sender" address. -
setSubject() public
Sets subject. -
setTemplate() public
Sets template. -
setTheme() public
Sets theme to use when rendering. -
setTo() public
Sets "to" address. -
setTransferEncoding() public
TransferEncoding setter. -
setTransport() public
Sets the transport. -
setViewRenderer() public
Sets view class for render. -
setViewVars() public
Sets variables to be set on render. -
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. -
viewRender() public
View class for render -
viewVars() public
Variables to be set on render
Method Detail
__construct() public ¶
__construct( array|string|null $config null )
Constructor
Parameters
- array|string|null $config optional null
- Array of configs, or string to load configs from app.php
_addEmail() protected ¶
_addEmail( string $varName , string|array $email , string $name )
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
_applyConfig() protected ¶
_applyConfig( string|array $config )
Apply the config to an instance
Parameters
- string|array $config
- Configuration options.
Throws
When using a configuration that doesn't exist.
_attachFiles() protected ¶
_attachFiles( string|null $boundary null )
Attach non-embedded files by adding file contents inside boundaries.
Parameters
- string|null $boundary optional null
- Boundary to use. If null, will default to $this->_boundary
Returns
An array of lines to add to the message
_attachInlineFiles() protected ¶
_attachInlineFiles( string|null $boundary null )
Attach inline/embedded files to the message.
Parameters
- string|null $boundary optional null
- Boundary to use. If null, will default to $this->_boundary
Returns
An array of lines to add to the message
_checkViewVars() protected ¶
_checkViewVars( mixed $item , string $key )
Iterates through hash to clean up and normalize.
Parameters
- mixed $item
- Reference to the view var value.
- string $key
- View var key.
_decode() protected ¶
_decode( string $text )
Decode the specified string
Parameters
- string $text
- String to decode
Returns
Decoded string
_encode() protected ¶
_encode( string $text )
Encode the specified string using the current charset
Parameters
- string $text
- String to encode
Returns
Encoded string
_encodeString() protected ¶
_encodeString( string $text , string $charset )
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
_formatAddress() protected ¶
_formatAddress( array $address )
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
_getContentTransferEncoding() protected ¶
_getContentTransferEncoding( )
Return the Content-Transfer Encoding value based on the set transferEncoding or set charset.
Returns
_getContentTypeCharset() protected ¶
_getContentTypeCharset( )
Return charset value for Content-Type.
Checks fallback/compatibility types which include workarounds for legacy japanese character sets.
Returns
_getTypes() protected ¶
_getTypes( )
Gets the text body types that are in this email message
Returns
Array of types. Valid types are 'text' and 'html'
_logDelivery() protected ¶
_logDelivery( array $contents )
Log the email message delivery.
Parameters
- array $contents
- The content with 'headers' and 'message' keys.
_readFile() protected ¶
_readFile( string $path )
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
File contents in base64 encoding
_render() protected ¶
_render( array $content )
Render the body of the email.
Parameters
- array $content
- Content to render
Returns
Email body ready to be sent
_renderTemplates() protected ¶
_renderTemplates( string $content )
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
The rendered content with html and text keys.
_setEmail() protected ¶
_setEmail( string $varName , string|array $email , string $name )
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
_setEmailSingle() protected ¶
_setEmailSingle( string $varName , string|array $email , string $name , string $throwMessage )
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
_validateEmail() protected ¶
_validateEmail( string $email , string $context )
Validate email address
Parameters
- string $email
- Email address to validate
- string $context
- Which property was set
Throws
If email address does not validate
_wrap() protected ¶
_wrap( string $message , integer $wrapLength Email::LINE_LENGTH_MUST )
Wrap the message to follow the RFC 2822 - 2.1.1
Parameters
- string $message
- Message to wrap
- integer $wrapLength optional Email::LINE_LENGTH_MUST
- The line length
Returns
Wrapped message
addAttachments() public ¶
addAttachments( string|array $attachments )
Add attachments
Parameters
- string|array $attachments
- String with the filename or array with filenames
Returns
$this
Throws
See
addBcc() public ¶
addBcc( string|array $email , string|null $name null )
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 null
- Name
Returns
$this
addCc() public ¶
addCc( string|array $email , string|null $name null )
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 null
- Name
Returns
$this
addHeaders() public ¶
addHeaders( array $headers )
Add header for the message
Parameters
- array $headers
- Headers to set.
Returns
$this
addTo() public ¶
addTo( string|array $email , string|null $name null )
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 null
- Name
Returns
$this
attachments() public ¶
attachments( string|array|null $attachments null )
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->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.
Deprecated
Parameters
- string|array|null $attachments optional null
- String with the filename or array with filenames
Returns
Throws
bcc() public ¶
bcc( string|array|null $email null , string|null $name null )
Bcc
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
cc() public ¶
cc( string|array|null $email null , string|null $name null )
Cc
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
charset() public ¶
charset( string|null $charset null )
Charset setter/getter
Deprecated
Parameters
- string|null $charset optional null
- Character set.
Returns
Charset
configTransport() public static ¶
configTransport( string|array $key , array|Cake\Mailer\AbstractTransport
|null $config 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
Deprecated
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 null Either an array of configuration data, or a transport instance.
Returns
Either null when setting or an array of data when reading.
Throws
When modifying an existing configuration.
configuredTransport() public static ¶
configuredTransport( )
Returns an array containing the named transport configurations
Deprecated
Returns
Array of configurations.
createFromArray() public ¶
createFromArray( array $config )
Configures an email instance object from serialized config.
Parameters
- array $config
- Email configuration array.
Returns
$this Configured email instance.
deliver() public static ¶
deliver( string|array|null $to null , string|null $subject null , string|array|null $message null , string|array $config 'default' , boolean $send true )
Static method to fast create an instance of \Cake\Mailer\Email
Parameters
- string|array|null $to optional null
- Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config
- string|null $subject optional null
- String of subject or null to use 'subject' from transport config
- string|array|null $message optional null
- String with message or array with variables to be used in render
- string|array $config optional 'default'
- String to use Email delivery profile from app.php or array with configs
- boolean $send optional true
- Send the email or just return the instance pre-configured
Returns
Throws
domain() public ¶
domain( string|null $domain null )
Domain as top level (the part after @)
Deprecated
Parameters
- string|null $domain optional null
- Manually set the domain for CLI mailing
Returns
dropTransport() public static ¶
dropTransport( string $key )
Delete transport configuration.
Deprecated
Parameters
- string $key
- The transport name to remove.
emailFormat() public ¶
emailFormat( string|null $format null )
Email format
Deprecated
Parameters
- string|null $format optional null
- Formatting string.
Returns
Throws
emailPattern() public ¶
emailPattern( string|boolean|null $regex false )
EmailPattern setter/getter
Deprecated
Parameters
- string|boolean|null $regex optional false
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
flatten() protected ¶
flatten( string|array $value )
Converts given value to string
Parameters
- string|array $value
- The value to convert
Returns
from() public ¶
from( string|array|null $email null , string|null $name null )
From
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
Throws
getAttachments() public ¶
getAttachments( )
Gets attachments to the email message.
Returns
Array of attachments.
getConfigTransport() public static ¶
getConfigTransport( string $key )
Gets current transport configuration.
Deprecated
Parameters
- string $key
- The configuration name to read.
Returns
Transport config.
getHeaders() public ¶
getHeaders( array $include [] )
Get list of headers
Includes:
from
replyTo
readReceipt
returnPath
to
cc
bcc
subject
Parameters
- array $include optional []
- List of headers.
Returns
getHelpers() public ¶
getHelpers( )
Gets helpers to be used when rendering.
Deprecated
Returns
getLayout() public ¶
getLayout( )
Gets layout.
Deprecated
Returns
getOriginalSubject() public ¶
getOriginalSubject( )
Get original subject without encoding
Returns
Original subject
getProfile() public ¶
getProfile( )
Gets the configuration profile to use for this instance.
Returns
getReadReceipt() public ¶
getReadReceipt( )
Gets Read Receipt (Disposition-Notification-To header).
Returns
getTheme() public ¶
getTheme( )
Gets theme to use when rendering.
Deprecated
Returns
getTransferEncoding() public ¶
getTransferEncoding( )
TransferEncoding getter.
Returns
Encoding
headerCharset() public ¶
headerCharset( string|null $charset null )
HeaderCharset setter/getter
Deprecated
Parameters
- string|null $charset optional null
- Character set.
Returns
Charset
helpers() public ¶
helpers( array|null $helpers null )
Helpers to be used in render
Deprecated
Parameters
- array|null $helpers optional null
- Helpers list.
Returns
jsonSerialize() public ¶
jsonSerialize( )
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
Serializable array of configuration properties.
Throws
When a view var object can not be properly serialized.
Implementation of
JsonSerializable::jsonSerialize()
message() public ¶
message( string|null $type null )
Get generated message (used by transport classes)
Parameters
- string|null $type optional null
- Use MESSAGE_* constants or null to return the full message as array
Returns
String if type is given, array if type is null
messageId() public ¶
messageId( boolean|string|null $message null )
Message-ID
Deprecated
Parameters
- boolean|string|null $message optional null
- True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID
Returns
Throws
profile() public ¶
profile( null|string|array $config null )
Get/Set the configuration profile to use for this instance.
Deprecated
Parameters
- null|string|array $config optional null
String with configuration name, or an array with config or null to return current config.
Returns
readReceipt() public ¶
readReceipt( string|array|null $email null , string|null $name null )
Read Receipt (Disposition-Notification-To header)
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
Throws
replyTo() public ¶
replyTo( string|array|null $email null , string|null $name null )
Reply-To
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
Throws
reset() public ¶
reset( )
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 )
Return Path
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
Throws
send() public ¶
send( string|array|null $content null )
Send an email using the specified content, template and layout
Parameters
- string|array|null $content optional null
- String with message or array with messages
Returns
Throws
sender() public ¶
sender( string|array|null $email null , string|null $name null )
Sender
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
Throws
serialize() public ¶
serialize( )
Serializes the Email object.
Returns
Implementation of
Serializable::serialize()
setAttachments() public ¶
setAttachments( string|array $attachments )
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->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
$this
Throws
setBcc() public ¶
setBcc( string|array $email , string|null $name null )
Sets "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 null
- Name
Returns
$this
setCc() public ¶
setCc( string|array $email , string|null $name null )
Sets "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 null
- Name
Returns
$this
setCharset() public ¶
setCharset( string|null $charset )
Charset setter.
Parameters
- string|null $charset
- Character set.
Returns
$this
setConfigTransport() public static ¶
setConfigTransport( string|array $key , array|Cake\Mailer\AbstractTransport
|null $config null )
Sets 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
Deprecated
Parameters
- string|array $key
The configuration name to write. Or an array of multiple transports to set.
-
array|
Cake\Mailer\AbstractTransport
|null $config optional null Either an array of configuration data, or a transport instance. Null when using key as array.
setDomain() public ¶
setDomain( string $domain )
Sets domain.
Domain as top level (the part after @).
Parameters
- string $domain
- Manually set the domain for CLI mailing.
Returns
$this
setEmailFormat() public ¶
setEmailFormat( string $format )
Sets email format.
Parameters
- string $format
- Formatting string.
Returns
$this
Throws
setEmailPattern() public ¶
setEmailPattern( string|null $regex )
EmailPattern 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
$this
setFrom() public ¶
setFrom( string|array $email , string|null $name null )
Sets "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 null
- Name
Returns
$this
Throws
setHeaderCharset() public ¶
setHeaderCharset( string|null $charset )
HeaderCharset setter.
Parameters
- string|null $charset
- Character set.
Returns
$this
setHeaders() public ¶
setHeaders( array $headers )
Sets headers for the message
Parameters
- array $headers
- Associative array containing headers to be set.
Returns
$this
setHelpers() public ¶
setHelpers( array $helpers )
Sets helpers to be used when rendering.
Deprecated
Parameters
- array $helpers
- Helpers list.
Returns
$this
setLayout() public ¶
setLayout( string|null $layout )
Sets layout.
Deprecated
Parameters
- string|null $layout
- Layout name or null to not use
Returns
$this
setMessageId() public ¶
setMessageId( boolean|string $message )
Sets message ID.
Parameters
- boolean|string $message
- True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID.
Returns
$this
Throws
setPriority() public ¶
setPriority( integer|null $priority )
Sets priority.
Parameters
- integer|null $priority
- 1 (highest) to 5 (lowest)
Returns
$this
setProfile() public ¶
setProfile( string|array $config )
Sets the configuration profile to use for this instance.
Parameters
- string|array $config
String with configuration name, or an array with config.
Returns
$this
setReadReceipt() public ¶
setReadReceipt( string|array $email , string|null $name null )
Sets 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 null
- Name
Returns
$this
Throws
setReplyTo() public ¶
setReplyTo( string|array $email , string|null $name null )
Sets "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 null
- Name
Returns
$this
Throws
setReturnPath() public ¶
setReturnPath( string|array $email , string|null $name null )
Return 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 null
- Name
Returns
$this
Throws
setSender() public ¶
setSender( string|array $email , string|null $name null )
Sets "sender" 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 null
- Name
Returns
$this
Throws
setSubject() public ¶
setSubject( string $subject )
Sets subject.
Parameters
- string $subject
- Subject string.
Returns
$this
setTemplate() public ¶
setTemplate( string|null $template )
Sets template.
Parameters
- string|null $template
- Template name or null to not use.
Returns
$this
setTheme() public ¶
setTheme( string $theme )
Sets theme to use when rendering.
Deprecated
Parameters
- string $theme
- Theme name.
Returns
$this
setTo() public ¶
setTo( string|array $email , string|null $name null )
Sets "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 null
- Name
Returns
$this
setTransferEncoding() public ¶
setTransferEncoding( string|null $encoding )
TransferEncoding setter.
Parameters
- string|null $encoding
- Encoding set.
Returns
$this
setTransport() public ¶
setTransport( string|Cake\Mailer\AbstractTransport
$name )
Sets 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
$this
Throws
When the chosen transport lacks a send method.
InvalidArgumentException
When $name is neither a string nor an object.
setViewRenderer() public ¶
setViewRenderer( string $viewClass )
Sets view class for render.
Parameters
- string $viewClass
- View class name.
Returns
$this
setViewVars() public ¶
setViewVars( array $viewVars )
Sets variables to be set on render.
Parameters
- array $viewVars
- Variables to set for view.
Returns
$this
subject() public ¶
subject( string|null $subject null )
Get/Set Subject.
Deprecated
Parameters
- string|null $subject optional null
- Subject string.
Returns
template() public ¶
template( boolean|string $template false , boolean|string $layout false )
Template and layout
Deprecated
Parameters
- boolean|string $template optional false
- Template name or null to not use
- boolean|string $layout optional false
- Layout name or null to not use
Returns
theme() public ¶
theme( string|null $theme null )
Theme to use when rendering
Deprecated
Parameters
- string|null $theme optional null
- Theme name.
Returns
to() public ¶
to( string|array|null $email null , string|null $name null )
To
Deprecated
Parameters
- string|array|null $email optional null
Null to get, String with email, Array with email as key, name as value or email as value (without name)
- string|null $name optional null
- Name
Returns
transport() public ¶
transport( string|Cake\Mailer\AbstractTransport
|null $name null )
Get/set the transport.
When setting the transport you can either use the name of a configured transport or supply a constructed transport.
Deprecated
Parameters
-
string|
Cake\Mailer\AbstractTransport
|null $name optional null Either the name of a configured transport, or a transport instance.
Returns
Throws
When the chosen transport lacks a send method.
InvalidArgumentException
When $name is neither a string nor an object.
unserialize() public ¶
unserialize( string $data )
Unserializes the Email object.
Parameters
- string $data
- Serialized string.
Returns
Implementation of
Serializable::unserialize()
viewRender() public ¶
viewRender( string|null $viewClass null )
View class for render
Deprecated
Parameters
- string|null $viewClass optional null
- View class name.
Returns
viewVars() public ¶
viewVars( array|null $viewVars null )
Variables to be set on render
Deprecated
Parameters
- array|null $viewVars optional null
- Variables to set for view.
Returns
Methods used from Cake\Core\StaticConfigTrait
config() public static ¶
config( string|array $key , array|null $config 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);
Deprecated
Parameters
- string|array $key
- The name of the configuration, or an array of multiple configs.
- array|null $config optional null
- An array of name => configuration data for adapter.
Returns
Null when adding configuration or an array of configuration data when reading.
Throws
When trying to modify an existing config.
configured() public static ¶
configured( )
Returns an array containing the named configurations
Returns
Array of configurations.
drop() public static ¶
drop( string $config )
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
Success of the removal, returns false when the config does not exist.
dsnClassMap() public static ¶
dsnClassMap( array $map null )
Returns or updates the DSN class map for this class.
Deprecated
Parameters
- array $map optional null
- Additions/edits to the class map to apply.
Returns
getConfig() public static ¶
getConfig( string $key )
Reads existing configuration.
Parameters
- string $key
- The name of the configuration.
Returns
Array of configuration data.
getDsnClassMap() public static ¶
getDsnClassMap( )
Returns the DSN class map for this class.
Returns
parseDsn() public static ¶
parseDsn( string $dsn )
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
The configuration array to be stored after parsing the DSN
Throws
If not passed a string, or passed an invalid string
setConfig() public static ¶
setConfig( string|array $key , array $config null )
This 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 $config optional null
- An array of name => configuration data for adapter.
Throws
When trying to modify an existing config.
LogicException
When trying to store an invalid structured config array.
setDsnClassMap() public static ¶
setDsnClassMap( array $map )
Updates the DSN class map for this class.
Parameters
- array $map
- Additions/edits to the class map to apply.
Methods used from Cake\View\ViewVarsTrait
createView() public ¶
createView( string|null $viewClass null )
Constructs the view class instance based on the current configuration.
Parameters
- string|null $viewClass optional null
- Optional namespaced class name of the View class to instantiate.
Returns
Throws
set() public ¶
set( string|array $name , mixed $value null )
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.
- mixed $value optional null
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
viewOptions() public ¶
viewOptions( string|array|null $options null , boolean $merge true )
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()
.
Deprecated
Parameters
- string|array|null $options optional null
- string or array of string to be appended to _validViewOptions.
- boolean $merge optional true
Whether to merge with or override existing valid View options. Defaults to
true
.
Returns
The updated view options as an array.
Properties detail
$_attachments ¶
List of files that should be attached to the email.
Only absolute paths
[]
$_bcc ¶
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
[]
$_cc ¶
Carbon Copy
List of email's that should receive a copy of the email. The Recipient WILL be able to see this list
[]
$_contentTypeCharset ¶
Define Content-Type charset name
[ 'ISO-2022-JP-MS' => 'ISO-2022-JP' ]
$_domain ¶
Domain for messageId generation. Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty
$_dsnClassMap ¶
An array mapping url schemes to fully qualified Transport class names. Unused.
Deprecated
[]
$_emailPattern ¶
Regex for email validation
If null, filter_var() will be used. Use the emailPattern() method to set a custom pattern.'
self::EMAIL_PATTERN
$_headers ¶
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
[]
$_profile ¶
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
[]
$_returnPath ¶
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
[]
$_transferEncodingAvailable ¶
Available encoding to be set for transfer.
[ '7bit', '8bit', 'base64', 'binary', 'quoted-printable' ]
$_transport ¶
Cake\Mailer\AbstractTransport
|null
The transport instance to use for sending mail.
$headerCharset ¶
Charset the email header is sent in If null, the $charset property will be used as default
$transferEncoding ¶
The email transfer encoding used. If null, the $charset property is used for determined the transfer encoding.