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
-
string
EMAIL_PATTERN'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui'
-
string
MESSAGE_BOTH'both'
-
string
MESSAGE_HTML'html'
-
string
MESSAGE_TEXT'text'
Properties summary
- $_profile protected
array
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
- $_transport protected
\Cake\Mailer\AbstractTransport|null
The transport instance to use for sending mail.
- $message protected
\Cake\Mailer\Message
Message instance.
- $messageClass protected
string
Message class name.
- $renderer protected
\Cake\Mailer\Renderer|null
Email 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
$this
Configured 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\Email
Instance of Cake\Mailer\Email
Throws
InvalidArgumentException
flatten() protected
flatten(mixed $value)
Converts given value to string
Parameters
-
string|array
$value The value to convert
Returns
string
getMessage() public
getMessage()
Get message instance.
Returns
\Cake\Mailer\Message
getProfile() public
getProfile()
Gets the configuration profile to use for this instance.
Returns
array
getRenderer() public
getRenderer()
Get email renderer.
Returns
\Cake\Mailer\Renderer
getTransport() public
getTransport()
Gets the transport.
Returns
\Cake\Mailer\AbstractTransport|null
getViewRenderer() public
getViewRenderer()
Gets view class for render.
Returns
string
getViewVars() public
getViewVars()
Gets variables to be set on render.
Returns
array
jsonSerialize() public
jsonSerialize()
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Returns
array
Serializable array of configuration properties.
Throws
Exception
When 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|array
String 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
$this
send() 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
array
Throws
BadMethodCallException
serialize() public
serialize()
Serializes the Email object.
Returns
string
setProfile() 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
$this
setRenderer() public
setRenderer(\Cake\Mailer\Renderer $renderer)
Set email renderer.
Parameters
-
\Cake\Mailer\Renderer
$renderer Render instance.
Returns
$this
setTransport() 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
$this
Throws
LogicException
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
unserialize() public
unserialize(mixed $data)
Unserializes the Email object.
Parameters
-
string
$data Serialized string.
viewBuilder() public
viewBuilder()
Get view builder.
Returns
\Cake\View\ViewBuilder
Property 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