Message class

Framework\Email\Message

Class Message.

Implements: Stringable

Defined in libraries/email/src/Message.php

Properties #

$mailer
The Mailer instance.
$boundary
The message boundary.
$headers
-
$attachments
A list of attachments with Content-Disposition equals `attachment`.
$inlineAttachments
An associative array of attachments with Content-Disposition equals `inline`.
$plainMessage
The plain text message.
$htmlMessage
The HTML message.
$to
An associative array used in the `To` header.
$cc
An associative array used in the `Cc` header.
$bcc
An associative array used in the `Bcc` header.
$replyTo
An associative array used in the `Reply-To` header.
$from
The values used in the `From` header.
$date
The message Date.

$mailer

protected \Framework\Email\Mailer $mailer

The Mailer instance.

$boundary

protected string $boundary

The message boundary.

$headers

protected array $headers = array ( 'mime-version' => '1.0', )

$attachments

protected array $attachments = array ( )

A list of attachments with Content-Disposition equals `attachment`.

$inlineAttachments

protected array $inlineAttachments = array ( )

An associative array of attachments with Content-Disposition equals `inline`.

$plainMessage

protected string $plainMessage

The plain text message.

$htmlMessage

protected string $htmlMessage

The HTML message.

$to

protected array $to = array ( )

An associative array used in the `To` header.

$cc

protected array $cc = array ( )

An associative array used in the `Cc` header.

$bcc

protected array $bcc = array ( )

An associative array used in the `Bcc` header.

$replyTo

protected array $replyTo = array ( )

An associative array used in the `Reply-To` header.

$from

protected array $from = array ( )

The values used in the `From` header.

$date

protected ?string $date = NULL

The message Date.

Methods #

__toString()
Render the Message as string.
addAttachment()
Add a filename to be attached.
addBcc()
Add address and name in the Bcc header.
addCc()
Add address and name in the Cc header.
addReplyTo()
Add address and name in the Reply-To header.
addTo()
Add address and name in the To header.
getAttachments()
Get a lis of attachments.
getBcc()
Get items of the Bcc header.
getBoundary()
Get the boundary.
getCc()
Get items of the Cc header.
getDate()
Get the Date header.
getFrom()
Get the From header items.
getFromAddress()
Get the email address of the From header.
getFromName()
Get the name of the From header.
getHeader()
Get a header.
getHeaderLines()
Get header lines.
getHeaders()
Get all headers set.
getHtmlMessage()
Get the text/html message.
getInlineAttachments()
Get a lis of inline attachments.
getPlainMessage()
Get the text/plain message.
getRecipients()
-
getReplyTo()
Get items of the Reply-To header.
getSubject()
Get the Subject header.
getTo()
Get items of the To header.
getXMailer()
Get the X-Mailer header.
getXPriority()
Get the X-Priority header.
removeBcc()
Remove all items of the Bcc header.
removeCc()
Remove all items of the Cc header.
removeFrom()
Remove all items of the From header.
removeHeader()
Remove a header.
removeReplyTo()
Remove all items of the Reply-To header.
removeTo()
Remove all items of the To header.
setBoundary()
Set the boundary.
setDate()
Set the Date header.
setFrom()
Set the From header.
setHeader()
Set a header.
setHtmlMessage()
Set the text/html message.
setInlineAttachment()
Set a filename to be attached inline (image).
setMailer()
Set the Mailer instance.
setPlainMessage()
Set the text/plain message.
setSubject()
Set the Subject header.
setXMailer()
Set the X-Mailer header.
setXPriority()
Set the X-Priority header.
formatAddress()
-
formatAddressList()
-
getCharset()
-
getContentType()
-
getCrlf()
-
prepareHeaders()
-
renderAttachments()
-
renderData()
-
renderHeaders()
-
renderHtmlMessage()
-
renderInlineAttachments()
-
renderMessage()
-
renderPlainMessage()
-

__toString()

public function __toString(): string

Render the Message as string.

Returns string

addAttachment()

public function addAttachment(string $filename): static

Add a filename to be attached.

Parameters
  • string $filename - The filename
Returns static

addBcc()

public function addBcc(string $address, ?string $name = NULL): static

Add address and name in the Bcc header.

Parameters
  • string $address - The email address
  • ?string $name - The name or null to don't set
Returns static

addCc()

public function addCc(string $address, ?string $name = NULL): static

Add address and name in the Cc header.

Parameters
  • string $address - The email address
  • ?string $name - The name or null to don't set
Returns static

addReplyTo()

public function addReplyTo(string $address, ?string $name = NULL): static

Add address and name in the Reply-To header.

Parameters
  • string $address - The email address
  • ?string $name - The name or null to don't set
Returns static

addTo()

public function addTo(string $address, ?string $name = NULL): static

Add address and name in the To header.

Parameters
  • string $address - The email address
  • ?string $name - The name or null to don't set
Returns static

getAttachments()

public function getAttachments(): array

Get a lis of attachments.

Returns array - Array of filenames

getBcc()

public function getBcc(): array

Get items of the Bcc header.

Returns array - Emails as keys and names as values

getBoundary()

public function getBoundary(): string

Get the boundary.

Returns string
throws
RandomException

getCc()

public function getCc(): array

Get items of the Cc header.

Returns array - Emails as keys and names as values

getDate()

public function getDate(): ?string

Get the Date header.

Returns ?string - The header value or null if not set

getFrom()

public function getFrom(): array

Get the From header items.

Returns array - email address in key 0 and name in key 1

getFromAddress()

public function getFromAddress(): ?string

Get the email address of the From header.

Returns ?string - The email or null if not set

getFromName()

public function getFromName(): ?string

Get the name of the From header.

Returns ?string - The name or null if not set

getHeader()

public function getHeader(string $name): ?string

Get a header.

Parameters
  • string $name - The header name
Returns ?string - The header value or null if not set

getHeaderLines()

public function getHeaderLines(): array

Get header lines.

Returns array - The header lines

getHeaders()

public function getHeaders(): array

Get all headers set.

Returns array - The header names, in lowercase, as keys and the values as values

getHtmlMessage()

public function getHtmlMessage(): ?string

Get the text/html message.

Returns ?string - The text/html message or null if not set

getInlineAttachments()

public function getInlineAttachments(): array

Get a lis of inline attachments.

Returns array - Content-IDs as keys and filenames as values

getPlainMessage()

public function getPlainMessage(): ?string

Get the text/plain message.

Returns ?string - The message or null if not set

getRecipients()

public function getRecipients(): array
Returns array

getReplyTo()

public function getReplyTo(): array

Get items of the Reply-To header.

Returns array - Emails as keys and names as values

getSubject()

public function getSubject(): ?string

Get the Subject header.

Returns ?string - The header value or null if not set

getTo()

public function getTo(): array

Get items of the To header.

Returns array - Emails as keys and names as values

getXMailer()

public function getXMailer(): ?string

Get the X-Mailer header.

Returns ?string - The X-Mailer header or null

getXPriority()

public function getXPriority(): ?\Framework\Email\XPriority

Get the X-Priority header.

Returns ?\Framework\Email\XPriority - The {@see XPriority} case or null

removeBcc()

public function removeBcc(): static

Remove all items of the Bcc header.

Returns static

removeCc()

public function removeCc(): static

Remove all items of the Cc header.

Returns static

removeFrom()

public function removeFrom(): static

Remove all items of the From header.

Returns static

removeHeader()

public function removeHeader(string $name): static

Remove a header.

Parameters
  • string $name - The header name
Returns static

removeReplyTo()

public function removeReplyTo(): static

Remove all items of the Reply-To header.

Returns static

removeTo()

public function removeTo(): static

Remove all items of the To header.

Returns static

setBoundary()

public function setBoundary(?string $boundary = NULL): static

Set the boundary.

Parameters
  • ?string $boundary
Returns static
throws
RandomException

setDate()

public function setDate(?DateTime $datetime = NULL): static

Set the Date header.

Parameters
  • ?DateTime $datetime - A custom DateTime or null to set the current datetime
Returns static

setFrom()

public function setFrom(string $address, ?string $name = NULL): static

Set the From header.

Parameters
  • string $address - The email address
  • ?string $name - The name or null to don't set
Returns static

setHeader()

public function setHeader(string $name, string $value): static

Set a header.

Parameters
  • string $name - The header name
  • string $value - The header value
Returns static

setHtmlMessage()

public function setHtmlMessage(string $message): static

Set the text/html message.

Parameters
  • string $message - The text/html message
Returns static

setInlineAttachment()

public function setInlineAttachment(string $filename, string $cid): static

Set a filename to be attached inline (image).

Parameters
  • string $filename - The filename
  • string $cid - The Content-ID
Returns static

setMailer()

public function setMailer(\Framework\Email\Mailer $mailer): static

Set the Mailer instance.

Parameters
  • \Framework\Email\Mailer $mailer - The Mailer instance
Returns static

setPlainMessage()

public function setPlainMessage(string $message): static

Set the text/plain message.

Parameters
  • string $message - The text/plain message
Returns static

setSubject()

public function setSubject(string $subject): static

Set the Subject header.

Parameters
  • string $subject - The header value
Returns static

setXMailer()

public function setXMailer(?string $xMailer = NULL): static

Set the X-Mailer header.

Parameters
  • ?string $xMailer - The X-Mailer header or null to set the default
Returns static

setXPriority()

public function setXPriority(\Framework\Email\XPriority $priority): static

Set the X-Priority header.

Parameters
  • \Framework\Email\XPriority $priority - The {@see XPriority} case
Returns static

formatAddress()

protected static function formatAddress(string $address, ?string $name = NULL): string
Parameters
  • string $address
  • ?string $name
Returns string

formatAddressList()

protected static function formatAddressList(array $addresses): string
Parameters
  • array $addresses
Returns string

getCharset()

protected function getCharset(): string
Returns string

getContentType()

protected function getContentType(string $filename): string
Parameters
  • string $filename
Returns string

getCrlf()

protected function getCrlf(): string
Returns string

prepareHeaders()

protected function prepareHeaders(): void
Returns void

renderAttachments()

protected function renderAttachments(): string
Returns string

renderData()

protected function renderData(): string
Returns string

renderHeaders()

protected function renderHeaders(): string
Returns string

renderHtmlMessage()

protected function renderHtmlMessage(): ?string
Returns ?string

renderInlineAttachments()

protected function renderInlineAttachments(): string
Returns string

renderMessage()

protected function renderMessage(string $message, string $contentType = 'text/html'): string
Parameters
  • string $message
  • string $contentType
Returns string

renderPlainMessage()

protected function renderPlainMessage(): ?string
Returns ?string