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
-
stringEMAIL_PATTERN'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui'Holds the regex pattern for email validation
-
stringMESSAGE_BOTH'both'
Type of message - BOTH
-
stringMESSAGE_HTML'html'
Type of message - HTML
-
stringMESSAGE_TEXT'text'
Type of message - TEXT
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|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
-
__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
voidcreateFromArray() public
createFromArray(array<string, mixed> $config): $this
Configures an email instance object from serialized config.
Parameters
-
array<string, mixed>$config Email configuration array.
Returns
$thisdeliver() 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\EmailThrows
InvalidArgumentExceptionflatten() protected
flatten(array<string>|string $value): string
Converts given value to string
Parameters
-
array<string>|string$value The value to convert
Returns
stringgetMessage() public
getMessage(): Cake\Mailer\Message
Get message instance.
Returns
Cake\Mailer\MessagegetProfile() 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\RenderergetTransport() public
getTransport(): Cake\Mailer\AbstractTransport|null
Gets the transport.
Returns
Cake\Mailer\AbstractTransport|nullgetViewRenderer() public
getViewRenderer(): string
Gets view class for render.
Returns
stringgetViewVars() 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
arrayThrows
ExceptionWhen 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|stringrender() public
render(array<string>|string|null $content = null): void
Render email.
Parameters
-
array<string>|string|null$content optional Content array or string
Returns
voidreset() public
reset(): $this
Reset all the internal variables to be able to send out a new email.
Returns
$thissend() 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
arrayThrows
BadMethodCallExceptionserialize() public
serialize(): string
Serializes the Email object.
Returns
stringsetProfile() 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
$thissetRenderer() public
setRenderer(Cake\Mailer\Renderer $renderer): $this
Set email renderer.
Parameters
-
Cake\Mailer\Renderer$renderer Render instance.
Returns
$thissetTransport() 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
$thisThrows
LogicExceptionWhen the chosen transport lacks a send method.
InvalidArgumentExceptionWhen $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
$thissetViewVars() 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
$thisunserialize() public
unserialize(string $data): void
Unserializes the Email object.
Parameters
-
string$data Serialized string.
Returns
voidviewBuilder() public
viewBuilder(): Cake\View\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<string, mixed>$_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.4/class-Cake.Mailer.Email.html