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 summary
-
stringEMAIL_PATTERN'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui' -
stringMESSAGE_BOTH'both' -
stringMESSAGE_HTML'html' -
stringMESSAGE_TEXT'text'
Properties summary
- $_profile protected
arrayA copy of the configuration profile for this instance. This copy can be modified with Email::profile().
- $_transport protected
\Cake\Mailer\AbstractTransport|nullThe transport instance to use for sending mail.
- $message protected
\Cake\Mailer\MessageMessage instance.
- $messageClass protected
stringMessage class name.
- $renderer protected
\Cake\Mailer\Renderer|nullEmail Renderer
Method Summary
- __callStatic() public static
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
- jsonSerialize() public
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Method Detail
__call() public
__call(string $method, array $args)
Magic method to forward method class to Email instance.
Parameters
-
string$method Method name.
-
array$args Method arguments
Returns
$this|mixed__callStatic() public static
__callStatic(mixed $name, mixed $arguments)
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
Parameters
-
string$name Method name.
-
array$arguments Method argument.
Returns
mixed__clone() public
__clone()
Clone Renderer instance when email object is cloned.
__construct() public
__construct(mixed $config)
Constructor
Parameters
-
array|string|null$config optional Array of configs, or string to load configs from app.php
_logDelivery() protected
_logDelivery(array $contents)
Log the email message delivery.
Parameters
-
array$contents The content with 'headers' and 'message' keys.
createFromArray() public
createFromArray(array $config)
Configures an email instance object from serialized config.
Parameters
-
array$config Email configuration array.
Returns
$thisConfigured email instance.
deliver() public static
deliver(mixed $to, ?string $subject, mixed $message, mixed $config, bool $send)
Static method to fast create an instance of \Cake\Mailer\Email
Parameters
-
string|array|null$to optional Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config
-
string|null$subject optional String of subject or null to use 'subject' from transport config
-
string|array|null$message optional String with message or array with variables to be used in render
-
string|array$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
\Cake\Mailer\EmailInstance of Cake\Mailer\Email
Throws
InvalidArgumentExceptionflatten() protected
flatten(mixed $value)
Converts given value to string
Parameters
-
string|array$value The value to convert
Returns
stringgetMessage() public
getMessage()
Get message instance.
Returns
\Cake\Mailer\MessagegetProfile() public
getProfile()
Gets the configuration profile to use for this instance.
Returns
arraygetRenderer() public
getRenderer()
Get email renderer.
Returns
\Cake\Mailer\RenderergetTransport() public
getTransport()
Gets the transport.
Returns
\Cake\Mailer\AbstractTransport|nullgetViewRenderer() public
getViewRenderer()
Gets view class for render.
Returns
stringgetViewVars() public
getViewVars()
Gets variables to be set on render.
Returns
arrayjsonSerialize() public
jsonSerialize()
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Returns
arraySerializable array of configuration properties.
Throws
ExceptionWhen a view var object can not be properly serialized.
message() public
message(?string $type)
Get generated message (used by transport classes)
Parameters
-
string|null$type optional Use MESSAGE_* constants or null to return the full message as array
Returns
string|arrayString if type is given, array if type is null
render() public
render(mixed $content)
Render email.
Parameters
-
string|array|null$content optional Content array or string
reset() public
reset()
Reset all the internal variables to be able to send out a new email.
Returns
$thissend() public
send(mixed $content)
Send an email using the specified content, template and layout
Parameters
-
string|array|null$content optional String with message or array with messages
Returns
arrayThrows
BadMethodCallExceptionserialize() public
serialize()
Serializes the Email object.
Returns
stringsetProfile() public
setProfile(mixed $config)
Sets the configuration profile to use for this instance.
Parameters
-
string|array$config String with configuration name, or an array with config.
Returns
$thissetRenderer() public
setRenderer(\Cake\Mailer\Renderer $renderer)
Set email renderer.
Parameters
-
\Cake\Mailer\Renderer$renderer Render instance.
Returns
$thissetTransport() public
setTransport(mixed $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
$thisThrows
LogicExceptionWhen the chosen transport lacks a send method.
InvalidArgumentExceptionWhen $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
$thissetViewVars() public
setViewVars(array $viewVars)
Sets variables to be set on render.
Parameters
-
array$viewVars Variables to set for view.
Returns
$thisunserialize() public
unserialize(mixed $data)
Unserializes the Email object.
Parameters
-
string$data Serialized string.
viewBuilder() public
viewBuilder()
Get view builder.
Returns
\Cake\View\ViewBuilderProperty Detail
$_profile protected
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
Type
array$_transport protected
The transport instance to use for sending mail.
Type
\Cake\Mailer\AbstractTransport|null$message protected
Message instance.
Type
\Cake\Mailer\Message$messageClass protected
Message class name.
Type
string$renderer protected
Email Renderer
Type
\Cake\Mailer\Renderer|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.Mailer.Email.html