Fr3nch13/CakePHP Utilities

Message
in package
implements JsonSerializable, Serializable

Email message class.

This class is used for sending Internet Message Format based on the standard outlined in https://www.rfc-editor.org/rfc/rfc2822.txt

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
LINE_LENGTH_MUST  = 998
Line length - no must more - RFC 2822 - 2.1.1
LINE_LENGTH_SHOULD  = 78
Line length - no should more - RFC 2822 - 2.1.1
MESSAGE_BOTH  = 'both'
Type of message - BOTH
MESSAGE_HTML  = 'html'
Type of message - HTML
MESSAGE_TEXT  = 'text'
Type of message - TEXT

Properties

$appCharset  : string|null
The application wide charset, used to encode headers and body
$attachments  : array<string, array<string|int, mixed>>
List of files that should be attached to the email.
$bcc  : array<string|int, mixed>
Blind Carbon Copy
$boundary  : string|null
If set, boundary to use for multipart mime messages
$cc  : array<string|int, mixed>
Carbon Copy
$charset  : string
Charset the email body is sent in
$charset8bit  : array<string|int, string>
8Bit character sets
$contentTypeCharset  : array<string, string>
Define Content-Type charset name
$domain  : string
Domain for messageId generation.
$emailFormat  : string
What format should the email be sent in
$emailFormatAvailable  : array<string|int, string>
Available formats to be sent.
$emailPattern  : string|null
Regex for email validation
$from  : array<string|int, mixed>
The mail which the email is sent from
$headerCharset  : string|null
Charset the email header is sent in If null, the $charset property will be used as default
$headers  : array<string|int, mixed>
Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5
$htmlMessage  : string
Html message
$message  : array<string|int, mixed>
Final message to send
$messageId  : string|bool
Message ID
$priority  : int|null
Contains the optional priority of the email.
$readReceipt  : array<string|int, mixed>
The read receipt email
$replyTo  : array<string|int, mixed>
List of email(s) that the recipient will reply to
$returnPath  : array<string|int, mixed>
The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user
$sender  : array<string|int, mixed>
The sender email
$subject  : string
The subject of the email
$textMessage  : string
Text message
$to  : array<string|int, mixed>
Recipient of the email
$transferEncoding  : string|null
The email transfer encoding used.
$transferEncodingAvailable  : array<string|int, string>
Available encoding to be set for transfer.

Methods

__construct()  : mixed
Constructor
__serialize()  : array<string|int, mixed>
Magic method used for serializing the Message object.
__unserialize()  : void
Magic method used to rebuild the Message object.
addAttachments()  : $this
Add attachments
addBcc()  : $this
Add "bcc" address.
addCc()  : $this
Add "cc" address.
addHeaders()  : $this
Add header for the message
addReplyTo()  : $this
Add "Reply-To" address.
addTo()  : $this
Add "To" address.
createFromArray()  : $this
Configures an email instance object from serialized config.
getAttachments()  : array<string, array<string|int, mixed>>
Gets attachments to the email message.
getBcc()  : array<string|int, mixed>
Gets "bcc" address.
getBody()  : array<string|int, mixed>
Get generated message body as array.
getBodyHtml()  : string
Get HTML body of message.
getBodyString()  : string
Get generated body as string.
getBodyText()  : string
Get text body of message.
getBodyTypes()  : array<string|int, mixed>
Gets the body types that are in this email message
getCc()  : array<string|int, mixed>
Gets "cc" address.
getCharset()  : string
Charset getter.
getContentTransferEncoding()  : string
Return the Content-Transfer Encoding value based on the set transferEncoding or set charset.
getContentTypeCharset()  : string
Return charset value for Content-Type.
getDomain()  : string
Gets domain.
getEmailFormat()  : string
Gets email format.
getEmailPattern()  : string|null
EmailPattern setter/getter
getFrom()  : array<string|int, mixed>
Gets "from" address.
getHeaderCharset()  : string
HeaderCharset getter.
getHeaders()  : array<string|int, string>
Get list of headers
getHeadersString()  : string
Get headers as string.
getMessageId()  : string|bool
Gets message ID.
getOriginalSubject()  : string
Get original subject without encoding
getPriority()  : int|null
Gets priority.
getReadReceipt()  : array<string|int, mixed>
Gets Read Receipt (Disposition-Notification-To header).
getReplyTo()  : array<string|int, mixed>
Gets "Reply-To" address.
getReturnPath()  : array<string|int, mixed>
Gets return path.
getSender()  : array<string|int, mixed>
Gets the "sender" address. See RFC link below for full explanation.
getSubject()  : string
Gets subject.
getTo()  : array<string|int, mixed>
Gets "to" address
getTransferEncoding()  : string|null
TransferEncoding getter.
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.
reset()  : $this
Reset all the internal variables to be able to send out a new email.
serialize()  : string
Serializes the Email object.
setAttachments()  : $this
Add attachments to the email message
setBcc()  : $this
Sets "bcc" address.
setBody()  : $this
Set message body.
setBodyHtml()  : $this
Set HTML body for message.
setBodyText()  : $this
Set text body for message.
setCc()  : $this
Sets "cc" address.
setCharset()  : $this
Charset setter.
setConfig()  : $this
Sets the configuration for this instance.
setDomain()  : $this
Sets domain.
setEmailFormat()  : $this
Sets email format.
setEmailPattern()  : $this
EmailPattern setter/getter
setFrom()  : $this
Sets "from" address.
setHeaderCharset()  : $this
HeaderCharset setter.
setHeaders()  : $this
Sets headers for the message
setMessageId()  : $this
Sets message ID.
setPriority()  : $this
Sets priority.
setReadReceipt()  : $this
Sets Read Receipt (Disposition-Notification-To header).
setReplyTo()  : $this
Sets "Reply-To" address.
setReturnPath()  : $this
Sets return path.
setSender()  : $this
Sets the "sender" address. See RFC link below for full explanation.
setSubject()  : $this
Sets subject.
setTo()  : $this
Sets "to" address.
setTransferEncoding()  : $this
TransferEncoding setter.
unserialize()  : void
Unserializes the Message object.
addEmail()  : $this
Add email
attachFiles()  : array<string|int, string>
Attach non-embedded files by adding file contents inside boundaries.
attachInlineFiles()  : array<string|int, string>
Attach inline/embedded files to the message.
createBoundary()  : void
Create unique boundary identifier
decodeForHeader()  : string
Decode the specified string
encodeForHeader()  : string
Encode the specified string using the current charset
encodeString()  : string
Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists
formatAddress()  : array<string|int, mixed>
Format addresses
generateMessage()  : array<string|int, string>
Generate full message.
readFile()  : string
Read the file contents and return a base64 version of the file contents.
setEmail()  : $this
Set email
setEmailSingle()  : $this
Set only 1 email
validateEmail()  : void
Validate email address
wrap()  : array<string|int, string>
Wrap the message to follow the RFC 2822 - 2.1.1

Constants

EMAIL_PATTERN

Holds the regex pattern for email validation

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

LINE_LENGTH_MUST

Line length - no must more - RFC 2822 - 2.1.1

public int LINE_LENGTH_MUST = 998

LINE_LENGTH_SHOULD

Line length - no should more - RFC 2822 - 2.1.1

public int LINE_LENGTH_SHOULD = 78

MESSAGE_BOTH

Type of message - BOTH

public string MESSAGE_BOTH = 'both'

MESSAGE_HTML

Type of message - HTML

public string MESSAGE_HTML = 'html'

MESSAGE_TEXT

Type of message - TEXT

public string MESSAGE_TEXT = 'text'

Properties

$appCharset

The application wide charset, used to encode headers and body

protected string|null $appCharset

$attachments

List of files that should be attached to the email.

protected array<string, array<string|int, mixed>> $attachments = []

Only absolute paths

$bcc

Blind Carbon Copy

protected array<string|int, mixed> $bcc = []

List of email's that should receive a copy of the email. The Recipient WILL NOT be able to see this list

$boundary

If set, boundary to use for multipart mime messages

protected string|null $boundary

$cc

Carbon Copy

protected array<string|int, mixed> $cc = []

List of email's that should receive a copy of the email. The Recipient WILL be able to see this list

$charset

Charset the email body is sent in

protected string $charset = 'utf-8'

$charset8bit

8Bit character sets

protected array<string|int, string> $charset8bit = ['UTF-8', 'SHIFT_JIS']

$contentTypeCharset

Define Content-Type charset name

protected array<string, string> $contentTypeCharset = ['ISO-2022-JP-MS' => 'ISO-2022-JP']

$domain

Domain for messageId generation.

protected string $domain = ''

Needs to be manually set for CLI mailing as env('HTTP_HOST') is empty

$emailFormat

What format should the email be sent in

protected string $emailFormat = self::MESSAGE_TEXT

$emailFormatAvailable

Available formats to be sent.

protected array<string|int, string> $emailFormatAvailable = [self::MESSAGE_TEXT, self::MESSAGE_HTML, self::MESSAGE_BOTH]

$emailPattern

Regex for email validation

protected string|null $emailPattern = self::EMAIL_PATTERN

If null, filter_var() will be used. Use the emailPattern() method to set a custom pattern.'

$from

The mail which the email is sent from

protected array<string|int, mixed> $from = []

$headerCharset

Charset the email header is sent in If null, the $charset property will be used as default

protected string|null $headerCharset

$headers

Associative array of a user defined headers Keys will be prefixed 'X-' as per RFC2822 Section 4.7.5

protected array<string|int, mixed> $headers = []

$htmlMessage

Html message

protected string $htmlMessage = ''

$message

Final message to send

protected array<string|int, mixed> $message = []

$messageId

Message ID

protected string|bool $messageId = true

$priority

Contains the optional priority of the email.

protected int|null $priority

$readReceipt

The read receipt email

protected array<string|int, mixed> $readReceipt = []

$replyTo

List of email(s) that the recipient will reply to

protected array<string|int, mixed> $replyTo = []

$returnPath

The mail that will be used in case of any errors like - Remote mailserver down - Remote user has exceeded his quota - Unknown user

protected array<string|int, mixed> $returnPath = []

$sender

The sender email

protected array<string|int, mixed> $sender = []

$subject

The subject of the email

protected string $subject = ''

$textMessage

Text message

protected string $textMessage = ''

$to

Recipient of the email

protected array<string|int, mixed> $to = []

$transferEncoding

The email transfer encoding used.

protected string|null $transferEncoding

If null, the $charset property is used for determined the transfer encoding.

$transferEncodingAvailable

Available encoding to be set for transfer.

protected array<string|int, string> $transferEncodingAvailable = ['7bit', '8bit', 'base64', 'binary', 'quoted-printable']

Methods

__construct()

Constructor

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

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

__serialize()

Magic method used for serializing the Message object.

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

__unserialize()

Magic method used to rebuild the Message object.

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

Data array.

addAttachments()

Add attachments

public addAttachments(array<string|int, mixed> $attachments) : $this
Parameters
$attachments : array<string|int, mixed>

Array of filenames.

Tags
throws
InvalidArgumentException
see
Email::setAttachments()
Return values
$this

addBcc()

Add "bcc" address.

public addBcc(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

addCc()

Add "cc" address.

public addCc(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

addHeaders()

Add header for the message

public addHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>

Headers to set.

Return values
$this

addReplyTo()

Add "Reply-To" address.

public addReplyTo(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

addTo()

Add "To" address.

public addTo(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

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

getAttachments()

Gets attachments to the email message.

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

Array of attachments.

getBcc()

Gets "bcc" address.

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

getBody()

Get generated message body as array.

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

getBodyHtml()

Get HTML body of message.

public getBodyHtml() : string
Return values
string

getBodyString()

Get generated body as string.

public getBodyString([string $eol = " " ]) : string
Parameters
$eol : string = " "

End of line string for imploding.

Tags
see
Message::getBody()
Return values
string

getBodyText()

Get text body of message.

public getBodyText() : string
Return values
string

getBodyTypes()

Gets the body types that are in this email message

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

Array of types. Valid types are Email::MESSAGE_TEXT and Email::MESSAGE_HTML

getCc()

Gets "cc" address.

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

getCharset()

Charset getter.

public getCharset() : string
Return values
string

Charset

getContentTransferEncoding()

Return the Content-Transfer Encoding value based on the set transferEncoding or set charset.

public getContentTransferEncoding() : string
Return values
string

getContentTypeCharset()

Return charset value for Content-Type.

public getContentTypeCharset() : string

Checks fallback/compatibility types which include workarounds for legacy japanese character sets.

Return values
string

getDomain()

Gets domain.

public getDomain() : string
Return values
string

getEmailFormat()

Gets email format.

public getEmailFormat() : string
Return values
string

getEmailPattern()

EmailPattern setter/getter

public getEmailPattern() : string|null
Return values
string|null

getFrom()

Gets "from" address.

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

getHeaderCharset()

HeaderCharset getter.

public getHeaderCharset() : string
Return values
string

Charset

getHeaders()

Get list of headers

public getHeaders([array<string|int, string> $include = [] ]) : array<string|int, string>

Includes:

  • from
  • replyTo
  • readReceipt
  • returnPath
  • to
  • cc
  • bcc
  • subject
Parameters
$include : array<string|int, string> = []

List of headers.

Return values
array<string|int, string>

getHeadersString()

Get headers as string.

public getHeadersString([array<string|int, string> $include = [] ][, string $eol = " " ][, Closure|null $callback = null ]) : string
Parameters
$include : array<string|int, string> = []

List of headers.

$eol : string = " "

End of line string for concatenating headers.

$callback : Closure|null = null

Callback to run each header value through before stringifying.

Tags
see
Message::getHeaders()
Return values
string

getMessageId()

Gets message ID.

public getMessageId() : string|bool
Return values
string|bool

getOriginalSubject()

Get original subject without encoding

public getOriginalSubject() : string
Return values
string

Original subject

getPriority()

Gets priority.

public getPriority() : int|null
Return values
int|null

getReadReceipt()

Gets Read Receipt (Disposition-Notification-To header).

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

getReplyTo()

Gets "Reply-To" address.

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

getReturnPath()

Gets return path.

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

getSubject()

Gets subject.

public getSubject() : string
Return values
string

getTo()

Gets "to" address

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

getTransferEncoding()

TransferEncoding getter.

public getTransferEncoding() : string|null
Return values
string|null

Encoding

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.

reset()

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

public reset() : $this
Return values
$this

serialize()

Serializes the Email object.

public serialize() : string
Return values
string

setAttachments()

Add attachments to the email message

public setAttachments(array<string|int, mixed> $attachments) : $this

Attachments can be defined in a few forms depending on how much control you need:

Attach a single file:

$this->setAttachments('path/to/file');

Attach a file with a different filename:

$this->setAttachments(['custom_name.txt' => 'path/to/file.txt']);

Attach a file and specify additional properties:

$this->setAttachments(['custom_name.png' => [
     'file' => 'path/to/file',
     'mimetype' => 'image/png',
     'contentId' => 'abc123',
     'contentDisposition' => false
   ]
]);

Attach a file from string and specify additional properties:

$this->setAttachments(['custom_name.png' => [
     'data' => file_get_contents('path/to/file'),
     'mimetype' => 'image/png'
   ]
]);

The contentId key allows you to specify an inline attachment. In your email text, you can use <img src="cid:abc123"/> to display the image inline.

The contentDisposition key allows you to disable the Content-Disposition header, this can improve attachment compatibility with outlook email clients.

Parameters
$attachments : array<string|int, mixed>

Array of filenames.

Tags
throws
InvalidArgumentException
Return values
$this

setBcc()

Sets "bcc" address.

public setBcc(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

setBody()

Set message body.

public setBody(array<string, string> $content) : $this
Parameters
$content : array<string, string>

Content array with keys "text" and/or "html" with content string of respective type.

Return values
$this

setBodyHtml()

Set HTML body for message.

public setBodyHtml(string $content) : $this
Parameters
$content : string

Content string

Return values
$this

setBodyText()

Set text body for message.

public setBodyText(string $content) : $this
Parameters
$content : string

Content string

Return values
$this

setCc()

Sets "cc" address.

public setCc(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

setCharset()

Charset setter.

public setCharset(string $charset) : $this
Parameters
$charset : string

Character set.

Return values
$this

setConfig()

Sets the configuration for this instance.

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

Config array.

Return values
$this

setDomain()

Sets domain.

public setDomain(string $domain) : $this

Domain as top level (the part after @).

Parameters
$domain : string

Manually set the domain for CLI mailing.

Return values
$this

setEmailFormat()

Sets email format.

public setEmailFormat(string $format) : $this
Parameters
$format : string

Formatting string.

Tags
throws
InvalidArgumentException
Return values
$this

setEmailPattern()

EmailPattern setter/getter

public setEmailPattern(string|null $regex) : $this
Parameters
$regex : string|null

The pattern to use for email address validation, null to unset the pattern and make use of filter_var() instead.

Return values
$this

setFrom()

Sets "from" address.

public setFrom(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Tags
throws
InvalidArgumentException
Return values
$this

setHeaderCharset()

HeaderCharset setter.

public setHeaderCharset(string|null $charset) : $this
Parameters
$charset : string|null

Character set.

Return values
$this

setHeaders()

Sets headers for the message

public setHeaders(array<string|int, mixed> $headers) : $this
Parameters
$headers : array<string|int, mixed>

Associative array containing headers to be set.

Return values
$this

setMessageId()

Sets message ID.

public setMessageId(string|bool $message) : $this
Parameters
$message : string|bool

True to generate a new Message-ID, False to ignore (not send in email), String to set as Message-ID.

Tags
throws
InvalidArgumentException
Return values
$this

setPriority()

Sets priority.

public setPriority(int|null $priority) : $this
Parameters
$priority : int|null

1 (highest) to 5 (lowest)

Return values
$this

setReadReceipt()

Sets Read Receipt (Disposition-Notification-To header).

public setReadReceipt(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Tags
throws
InvalidArgumentException
Return values
$this

setReplyTo()

Sets "Reply-To" address.

public setReplyTo(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Tags
throws
InvalidArgumentException
Return values
$this

setReturnPath()

Sets return path.

public setReturnPath(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Tags
throws
InvalidArgumentException
Return values
$this

setSender()

Sets the "sender" address. See RFC link below for full explanation.

public setSender(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Tags
throws
InvalidArgumentException
link
https://tools.ietf.org/html/rfc2822.html#section-3.6.2
Return values
$this

setSubject()

Sets subject.

public setSubject(string $subject) : $this
Parameters
$subject : string

Subject string.

Return values
$this

setTo()

Sets "to" address.

public setTo(array<string|int, mixed>|string $email[, string|null $name = null ]) : $this
Parameters
$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null = null

Name

Return values
$this

setTransferEncoding()

TransferEncoding setter.

public setTransferEncoding(string|null $encoding) : $this
Parameters
$encoding : string|null

Encoding set.

Tags
throws
InvalidArgumentException
Return values
$this

unserialize()

Unserializes the Message object.

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

Serialized string.

addEmail()

Add email

protected addEmail(string $varName, array<string|int, mixed>|string $email, string|null $name) : $this
Parameters
$varName : string

Property name

$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null

Name

Tags
throws
InvalidArgumentException
Return values
$this

attachFiles()

Attach non-embedded files by adding file contents inside boundaries.

protected attachFiles([string|null $boundary = null ]) : array<string|int, string>
Parameters
$boundary : string|null = null

Boundary to use. If null, will default to $this->boundary

Return values
array<string|int, string>

An array of lines to add to the message

attachInlineFiles()

Attach inline/embedded files to the message.

protected attachInlineFiles([string|null $boundary = null ]) : array<string|int, string>
Parameters
$boundary : string|null = null

Boundary to use. If null, will default to $this->boundary

Return values
array<string|int, string>

An array of lines to add to the message

createBoundary()

Create unique boundary identifier

protected createBoundary() : void

decodeForHeader()

Decode the specified string

protected decodeForHeader(string $text) : string
Parameters
$text : string

String to decode

Return values
string

Decoded string

encodeForHeader()

Encode the specified string using the current charset

protected encodeForHeader(string $text) : string
Parameters
$text : string

String to encode

Return values
string

Encoded string

encodeString()

Translates a string for one charset to another if the App.encoding value differs and the mb_convert_encoding function exists

protected encodeString(string $text, string $charset) : string
Parameters
$text : string

The text to be converted

$charset : string

the target encoding

Return values
string

formatAddress()

Format addresses

protected formatAddress(array<string|int, mixed> $address) : array<string|int, mixed>

If the address contains non alphanumeric/whitespace characters, it will be quoted as characters like : and , are known to cause issues in address header fields.

Parameters
$address : array<string|int, mixed>

Addresses to format.

Return values
array<string|int, mixed>

generateMessage()

Generate full message.

protected generateMessage() : array<string|int, string>
Return values
array<string|int, string>

readFile()

Read the file contents and return a base64 version of the file contents.

protected readFile(UploadedFileInterface|string $file) : string
Parameters
$file : UploadedFileInterface|string

The absolute path to the file to read or UploadedFileInterface instance.

Return values
string

File contents in base64 encoding

setEmail()

Set email

protected setEmail(string $varName, array<string|int, mixed>|string $email, string|null $name) : $this
Parameters
$varName : string

Property name

$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null

Name

Tags
throws
InvalidArgumentException
Return values
$this

setEmailSingle()

Set only 1 email

protected setEmailSingle(string $varName, array<string|int, mixed>|string $email, string|null $name, string $throwMessage) : $this
Parameters
$varName : string

Property name

$email : array<string|int, mixed>|string

String with email, Array with email as key, name as value or email as value (without name)

$name : string|null

Name

$throwMessage : string

Exception message

Tags
throws
InvalidArgumentException
Return values
$this

validateEmail()

Validate email address

protected validateEmail(string $email, string $context) : void
Parameters
$email : string

Email address to validate

$context : string

Which property was set

Tags
throws
InvalidArgumentException

If email address does not validate

wrap()

Wrap the message to follow the RFC 2822 - 2.1.1

protected wrap([string|null $message = null ][, int $wrapLength = self::LINE_LENGTH_MUST ]) : array<string|int, string>
Parameters
$message : string|null = null

Message to wrap

$wrapLength : int = self::LINE_LENGTH_MUST

The line length

Return values
array<string|int, string>

Wrapped message


        
On this page

Search results