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.
Deprecated: 4.0.0 This class will be removed in CakePHP 5.0, use {@link \Cake\Mailer\Mailer} instead.
Constants
Property Summary
-
$_profile protected
array<string, mixed>
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
-
__call() public
Magic method to forward method class to Email instance.
-
__callStatic() public static
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
-
__clone() public
Clone Renderer instance when email object is cloned.
-
__construct() public
Constructor
-
__serialize() public
Magic method used for serializing the Email object.
-
__unserialize() public
Magic method used to rebuild the Email object.
-
_logDelivery() protected
Log the email message delivery.
-
createFromArray() public
Configures an email instance object from serialized config.
-
deliver() public static
Static method to fast create an instance of \Cake\Mailer\Email
-
flatten() protected
Converts given value to string
-
getMessage() public
Get message instance.
-
getProfile() public
Gets the configuration profile to use for this instance.
-
getRenderer() public
Get email renderer.
-
getTransport() public
Gets the transport.
-
getViewRenderer() public
Gets view class for render.
-
getViewVars() public
Gets variables to be set on 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)
-
render() public
Render email.
-
reset() public
Reset all the internal variables to be able to send out a new email.
-
send() public
Send an email using the specified content, template and layout
-
serialize() public
Serializes the Email object.
-
setProfile() public
Sets the configuration profile to use for this instance.
-
setRenderer() public
Set email renderer.
-
setTransport() public
Sets the transport.
-
setViewRenderer() public
Sets view class for render.
-
setViewVars() public
Sets variables to be set on render.
-
unserialize() public
Unserializes the Email object.
-
viewBuilder() public
Get view builder.
Method Detail
__call() ¶ public
__call(string $method, array $args): $this|mixed
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(string $name, array $arguments): mixed
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(): void
Clone Renderer instance when email object is cloned.
Returns
void
__construct() ¶ public
__construct(array<string, mixed>|string|null $config = null)
Constructor
Parameters
-
array<string, mixed>|string|null
$config optional Array of configs, or string to load configs from app.php
__serialize() ¶ public
__serialize(): array
Magic method used for serializing the Email object.
Returns
array
__unserialize() ¶ public
__unserialize(array $data): void
Magic method used to rebuild the Email object.
Parameters
-
array
$data Data array.
Returns
void
_logDelivery() ¶ protected
_logDelivery(array<string, string> $contents): void
Log the email message delivery.
Parameters
-
array<string, string>
$contents The content with 'headers' and 'message' keys.
Returns
void
createFromArray() ¶ public
createFromArray(array<string, mixed> $config): $this
Configures an email instance object from serialized config.
Parameters
-
array<string, mixed>
$config Email configuration array.
Returns
$this
deliver() ¶ public static
deliver(array|string|null $to = null, string|null $subject = null, array|string|null $message = null, array<string, mixed>|string $config = 'default', bool $send = true): Cake\Mailer\Email
Static method to fast create an instance of \Cake\Mailer\Email
Parameters
-
array|string|null
$to optional Address to send ({@see \Cake\Mailer\Email::setTo()}). 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
-
array|string|null
$message optional String with message or array with variables to be used in render
-
array<string, mixed>|string
$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
Throws
InvalidArgumentException
flatten() ¶ protected
flatten(array<string>|string $value): string
Converts given value to string
Parameters
-
array<string>|string
$value The value to convert
Returns
string
getMessage() ¶ public
getMessage(): Cake\Mailer\Message
Get message instance.
Returns
Cake\Mailer\Message
getProfile() ¶ public
getProfile(): array<string, mixed>
Gets the configuration profile to use for this instance.
Returns
array<string, mixed>
getRenderer() ¶ public
getRenderer(): Cake\Mailer\Renderer
Get email renderer.
Returns
Cake\Mailer\Renderer
getTransport() ¶ public
getTransport(): Cake\Mailer\AbstractTransport|null
Gets the transport.
Returns
Cake\Mailer\AbstractTransport|null
getViewVars() ¶ public
getViewVars(): array<string, mixed>
Gets variables to be set on render.
Returns
array<string, mixed>
jsonSerialize() ¶ public
jsonSerialize(): array
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Returns
array
Throws
Exception
When a view var object can not be properly serialized.
message() ¶ public
message(string|null $type = null): array|string
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
array|string
render() ¶ public
render(array<string>|string|null $content = null): void
Render email.
Parameters
-
array<string>|string|null
$content optional Content array or string
Returns
void
reset() ¶ public
reset(): $this
Reset all the internal variables to be able to send out a new email.
Returns
$this
send() ¶ public
send(array<string>|string|null $content = null): array
Send an email using the specified content, template and layout
Parameters
-
array<string>|string|null
$content optional String with message or array with messages
Returns
array
Throws
BadMethodCallException
setProfile() ¶ public
setProfile(array<string, mixed>|string $config): $this
Sets the configuration profile to use for this instance.
Parameters
-
array<string, mixed>|string
$config String with configuration name, or an array with config.
Returns
$this
setRenderer() ¶ public
setRenderer(Cake\Mailer\Renderer $renderer): $this
Set email renderer.
Parameters
-
Cake\Mailer\Renderer
$renderer Render instance.
Returns
$this
setTransport() ¶ public
setTransport(Cake\Mailer\AbstractTransport|string $name): $this
Sets the transport.
When setting the transport you can either use the name of a configured transport or supply a constructed transport.
Parameters
-
Cake\Mailer\AbstractTransport|string
$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): $this
Sets view class for render.
Parameters
-
string
$viewClass View class name.
Returns
$this
setViewVars() ¶ public
setViewVars(array<string, mixed> $viewVars): $this
Sets variables to be set on render.
Parameters
-
array<string, mixed>
$viewVars Variables to set for view.
Returns
$this
unserialize() ¶ public
unserialize(string $data): void
Unserializes the Email object.
Parameters
-
string
$data Serialized string.
Returns
void
viewBuilder() ¶ public
viewBuilder(): Cake\View\ViewBuilder
Get view builder.
Returns
Cake\View\ViewBuilder