Fr3nch13/CakePHP Utilities

Email
in package
implements JsonSerializable, Serializable

CakePHP Email class.

This class will be removed in CakePHP 5.0, use instead.

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.

Tags
mixin

\Cake\Mailer\Mailer

Table of Contents

Interfaces

JsonSerializable
Serializable

Constants

EMAIL_PATTERN  = '/^((?:[\p{L}0-9.!#$%&\'*+\/=?^_`{|}~-]+)*@[\p{L}0-9-._]+)$/ui'
Holds the regex pattern for email validation
MESSAGE_BOTH  = 'both'
Type of message - BOTH
MESSAGE_HTML  = 'html'
Type of message - HTML
MESSAGE_TEXT  = 'text'
Type of message - TEXT

Properties

$_profile  : array<string, mixed>
A copy of the configuration profile for this instance. This copy can be modified with Email::profile().
$_transport  : AbstractTransport|null
The transport instance to use for sending mail.
$message  : Message
Message instance.
$messageClass  : string
Message class name.
$renderer  : Renderer|null
Email Renderer

Methods

__call()  : $this|mixed
Magic method to forward method class to Email instance.
__callStatic()  : mixed
Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.
__clone()  : void
Clone Renderer instance when email object is cloned.
__construct()  : mixed
Constructor
__serialize()  : array<string|int, mixed>
Magic method used for serializing the Email object.
__unserialize()  : void
Magic method used to rebuild the Email object.
createFromArray()  : $this
Configures an email instance object from serialized config.
deliver()  : Email
Static method to fast create an instance of \Cake\Mailer\Email
getMessage()  : Message
Get message instance.
getProfile()  : array<string, mixed>
Gets the configuration profile to use for this instance.
getRenderer()  : Renderer
Get email renderer.
getTransport()  : AbstractTransport|null
Gets the transport.
getViewRenderer()  : string
Gets view class for render.
getViewVars()  : array<string, mixed>
Gets variables to be set on render.
jsonSerialize()  : array<string|int, mixed>
Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.
message()  : array<string|int, mixed>|string
Get generated message (used by transport classes)
render()  : void
Render email.
reset()  : $this
Reset all the internal variables to be able to send out a new email.
send()  : array<string|int, mixed>
Send an email using the specified content, template and layout
serialize()  : string
Serializes the Email object.
setProfile()  : $this
Sets the configuration profile to use for this instance.
setRenderer()  : $this
Set email renderer.
setTransport()  : $this
Sets the transport.
setViewRenderer()  : $this
Sets view class for render.
setViewVars()  : $this
Sets variables to be set on render.
unserialize()  : void
Unserializes the Email object.
viewBuilder()  : ViewBuilder
Get view builder.
_logDelivery()  : void
Log the email message delivery.
flatten()  : string
Converts given value to string

Constants

EMAIL_PATTERN

Holds the regex pattern for email validation

Use Message::EMAIL_PATTERN instead.

public string EMAIL_PATTERN = '/^((?:[\p{L}0-9.!#$%&\'*+\/=?^_`{|}~-]+)*@[\p{L}0-9-._]+)$/ui'

MESSAGE_BOTH

Type of message - BOTH

Use Message::MESSAGE_BOTH instead.

public string MESSAGE_BOTH = 'both'

MESSAGE_HTML

Type of message - HTML

Use Message::MESSAGE_HTML instead.

public string MESSAGE_HTML = 'html'

MESSAGE_TEXT

Type of message - TEXT

Use Message::MESSAGE_TEXT instead.

public string MESSAGE_TEXT = 'text'

Properties

$_profile

A copy of the configuration profile for this instance. This copy can be modified with Email::profile().

protected array<string, mixed> $_profile = []

$messageClass

Message class name.

protected string $messageClass = \Cake\Mailer\Message::class
Tags
psalm-var

class-string<\Cake\Mailer\Message>

Methods

__call()

Magic method to forward method class to Email instance.

public __call(string $method, array<string|int, mixed> $args) : $this|mixed
Parameters
$method : string

Method name.

$args : array<string|int, mixed>

Method arguments

Return values
$this|mixed

__callStatic()

Proxy all static method calls (for methods provided by StaticConfigTrait) to Mailer.

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string

Method name.

$arguments : array<string|int, mixed>

Method argument.

__clone()

Clone Renderer instance when email object is cloned.

public __clone() : void

__construct()

Constructor

public __construct([array<string, mixed>|string|null $config = null ]) : mixed
Parameters
$config : array<string, mixed>|string|null = null

Array of configs, or string to load configs from app.php

__serialize()

Magic method used for serializing the Email object.

public __serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unserialize()

Magic method used to rebuild the Email object.

public __unserialize(array<string|int, mixed> $data) : void
Parameters
$data : array<string|int, mixed>

Data array.

createFromArray()

Configures an email instance object from serialized config.

public createFromArray(array<string, mixed> $config) : $this
Parameters
$config : array<string, mixed>

Email configuration array.

Return values
$this

deliver()

Static method to fast create an instance of \Cake\Mailer\Email

public static deliver([array<string|int, mixed>|string|null $to = null ][, string|null $subject = null ][, array<string|int, mixed>|string|null $message = null ][, array<string, mixed>|string $config = 'default' ][, bool $send = true ]) : Email
Parameters
$to : array<string|int, mixed>|string|null = null

Address to send (Email::setTo()). If null, will try to use 'to' from transport config

$subject : string|null = null

String of subject or null to use 'subject' from transport config

$message : array<string|int, mixed>|string|null = null

String with message or array with variables to be used in render

$config : array<string, mixed>|string = 'default'

String to use Email delivery profile from app.php or array with configs

$send : bool = true

Send the email or just return the instance pre-configured

Tags
throws
InvalidArgumentException
Return values
Email

getProfile()

Gets the configuration profile to use for this instance.

public getProfile() : array<string, mixed>
Return values
array<string, mixed>

getViewRenderer()

Gets view class for render.

public getViewRenderer() : string
Tags
psalm-suppress

InvalidNullableReturnType

Return values
string

getViewVars()

Gets variables to be set on render.

public getViewVars() : array<string, mixed>
Return values
array<string, mixed>

jsonSerialize()

Serializes the email object to a value that can be natively serialized and re-used to clone this email instance.

public jsonSerialize() : array<string|int, mixed>
Tags
throws
Exception

When a view var object can not be properly serialized.

Return values
array<string|int, mixed>

Serializable array of configuration properties.

message()

Get generated message (used by transport classes)

public message([string|null $type = null ]) : array<string|int, mixed>|string
Parameters
$type : string|null = null

Use MESSAGE_* constants or null to return the full message as array

Return values
array<string|int, mixed>|string

String if type is given, array if type is null

render()

Render email.

public render([array<string|int, string>|string|null $content = null ]) : void
Parameters
$content : array<string|int, string>|string|null = null

Content array or string

reset()

Reset all the internal variables to be able to send out a new email.

public reset() : $this
Return values
$this

send()

Send an email using the specified content, template and layout

public send([array<string|int, string>|string|null $content = null ]) : array<string|int, mixed>
Parameters
$content : array<string|int, string>|string|null = null

String with message or array with messages

Tags
throws
BadMethodCallException
psalm-return

array{headers: string, message: string}

Return values
array<string|int, mixed>

serialize()

Serializes the Email object.

public serialize() : string
Return values
string

setProfile()

Sets the configuration profile to use for this instance.

public setProfile(array<string, mixed>|string $config) : $this
Parameters
$config : array<string, mixed>|string

String with configuration name, or an array with config.

Return values
$this

setRenderer()

Set email renderer.

public setRenderer(Renderer $renderer) : $this
Parameters
$renderer : Renderer

Render instance.

Return values
$this

setTransport()

Sets the transport.

public setTransport(AbstractTransport|string $name) : $this

When setting the transport you can either use the name of a configured transport or supply a constructed transport.

Parameters
$name : AbstractTransport|string

Either the name of a configured transport, or a transport instance.

Tags
throws
LogicException

When the chosen transport lacks a send method.

throws
InvalidArgumentException

When $name is neither a string nor an object.

Return values
$this

setViewRenderer()

Sets view class for render.

public setViewRenderer(string $viewClass) : $this
Parameters
$viewClass : string

View class name.

Return values
$this

setViewVars()

Sets variables to be set on render.

public setViewVars(array<string, mixed> $viewVars) : $this
Parameters
$viewVars : array<string, mixed>

Variables to set for view.

Return values
$this

unserialize()

Unserializes the Email object.

public unserialize(string $data) : void
Parameters
$data : string

Serialized string.

_logDelivery()

Log the email message delivery.

protected _logDelivery(array<string, string> $contents) : void
Parameters
$contents : array<string, string>

The content with 'headers' and 'message' keys.

flatten()

Converts given value to string

protected flatten(array<string|int, string>|string $value) : string
Parameters
$value : array<string|int, string>|string

The value to convert

Return values
string

        
On this page

Search results