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 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.
string
'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui'
Holds the regex pattern for email validation
string
'both'
Type of message - BOTH
string
'html'
Type of message - HTML
string
'text'
Type of message - TEXT
array<string, mixed>
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
Cake\Mailer\AbstractTransport|null
The transport instance to use for sending mail.
Cake\Mailer\Message
Message instance.
string
Message class name.
Cake\Mailer\Renderer|null
Email Renderer
Magic method to forward method class to Email instance.
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
Clone Renderer instance when email object is cloned.
Constructor
Magic method used for serializing the Email object.
Magic method used to rebuild the Email object.
Log the email message delivery.
Configures an email instance object from serialized config.
Static method to fast create an instance of \Cake\Mailer\Email
Converts given value to string
Get message instance.
Gets the configuration profile to use for this instance.
Get email renderer.
Gets the transport.
Gets view class for render.
Gets variables to be set on render.
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
Get generated message (used by transport classes)
Render email.
Reset all the internal variables to be able to send out a new email.
Send an email using the specified content, template and layout
Serializes the Email object.
Sets the configuration profile to use for this instance.
Set email renderer.
Sets the transport.
Sets view class for render.
Sets variables to be set on render.
Unserializes the Email object.
Get view builder.
__call(string $method, array $args): $this|mixed
Magic method to forward method class to Email instance.
string
$method Method name.
array
$args Method arguments
$this|mixed
__callStatic(string $name, array $arguments): mixed
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
string
$name Method name.
array
$arguments Method argument.
mixed
__clone(): void
Clone Renderer instance when email object is cloned.
void
__construct(array<string, mixed>|string|null $config = null)
Constructor
array<string, mixed>|string|null
$config optional Array of configs, or string to load configs from app.php
__serialize(): array
Magic method used for serializing the Email object.
array
__unserialize(array $data): void
Magic method used to rebuild the Email object.
array
$data Data array.
void
_logDelivery(array<string, string> $contents): void
Log the email message delivery.
array<string, string>
$contents The content with 'headers' and 'message' keys.
void
createFromArray(array<string, mixed> $config): $this
Configures an email instance object from serialized config.
array<string, mixed>
$config Email configuration array.
$this
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
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
Cake\Mailer\Email
InvalidArgumentException
flatten(array<string>|string $value): string
Converts given value to string
array<string>|string
$value The value to convert
string
getMessage(): Cake\Mailer\Message
Get message instance.
Cake\Mailer\Message
getProfile(): array<string, mixed>
Gets the configuration profile to use for this instance.
array<string, mixed>
getRenderer(): Cake\Mailer\Renderer
Get email renderer.
Cake\Mailer\Renderer
getTransport(): Cake\Mailer\AbstractTransport|null
Gets the transport.
Cake\Mailer\AbstractTransport|null
getViewRenderer(): string
Gets view class for render.
string
getViewVars(): array<string, mixed>
Gets variables to be set on render.
array<string, mixed>
jsonSerialize(): array
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
array
Exception
message(string|null $type = null): array|string
Get generated message (used by transport classes)
string|null
$type optional Use MESSAGE_* constants or null to return the full message as array
array|string
render(array<string>|string|null $content = null): void
Render email.
array<string>|string|null
$content optional Content array or string
void
reset(): $this
Reset all the internal variables to be able to send out a new email.
$this
send(array<string>|string|null $content = null): array
Send an email using the specified content, template and layout
array<string>|string|null
$content optional String with message or array with messages
array
BadMethodCallException
serialize(): string
Serializes the Email object.
string
setProfile(array<string, mixed>|string $config): $this
Sets the configuration profile to use for this instance.
array<string, mixed>|string
$config String with configuration name, or an array with config.
$this
setRenderer(Cake\Mailer\Renderer $renderer): $this
Set email renderer.
Cake\Mailer\Renderer
$renderer Render instance.
$this
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.
Cake\Mailer\AbstractTransport|string
$name Either the name of a configured transport, or a transport instance.
$this
LogicException
InvalidArgumentException
setViewRenderer(string $viewClass): $this
Sets view class for render.
string
$viewClass View class name.
$this
setViewVars(array<string, mixed> $viewVars): $this
Sets variables to be set on render.
array<string, mixed>
$viewVars Variables to set for view.
$this
unserialize(string $data): void
Unserializes the Email object.
string
$data Serialized string.
void
viewBuilder(): Cake\View\ViewBuilder
Get view builder.
Cake\View\ViewBuilder
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
array<string, mixed>
The transport instance to use for sending mail.
Cake\Mailer\AbstractTransport|null
Message instance.
Cake\Mailer\Message
Message class name.
string
Email Renderer
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