An Email Message

Messages are sent out for various reasons, including for events such as invoice creation and Email Campaigns.

The Message class allows you to interact with the message to update any respective properties before use.

class Message

Constants

HEADER_MARKER

FOOTER_MARKER

RFC3834_HEADERS

RECIPIENT_TYPES

Properties summary

Type Property Description
protected $type
protected $templateName
protected $from
protected $to
protected $cc
protected $bcc
protected $replyTo
protected $subject
protected $body
protected $bodyPlainText
protected $attachments
protected $headers
protected $defaultEmailHeadersByType Default email headers which should be provided for use in each email. This should be broken up into email types.

Methods summary

Return Type Method Name Description
__construct() -
$this setEmailLogId($id) Set the ID of the email relative to tblemails.id
static Message createFromTemplate(Template $template) Build an Email Message from a predefined Template
$this setType(string $type) Set the Email Type. e.g. 'general'
string getType() Retrieve the Message type
$this setTemplateName(string $templateName) Set the Message template name
string getTemplateName() Retrieve the Message template name
$this addRecipient(string $kind, string $email, string $name = '') Add a recipient for the Message
$this clearRecipients(string $kind) Clear recipients for a specific kind
$this setFromName(string $name) Set the "From" name for the Message
string getFromName() Retrieve the "From" name for the message
$this setFromEmail(string $email) Set the sender Email Address for the Message
mixed getFromEmail() Retrieve the sender Email Address for the Message
string getFormattedFrom() Retrieve the sender Email Address and Name formatted for sending. e.g. 'John Doejohn@example.net'
$this setReplyTo(string $email, string $name = '') Set the Reply To address and name for the Message
array getReplyTo() Retrieve the Reply To address and name for the Message
getReplyToName() -
getReplyToEmail() -
string getFormattedReplyTo() Retrieve the reply-to Email Address and Name formatted for sending. e.g. 'John Doejohn@example.net'
array getRecipients(string $kind) Retrieve the recipients for the Message
array|string getFormattedRecipients($kind) Retrieve the sender Email Addresses and Names formatted for sending. e.g. 'John Doe john@example.net'
$this setSubject(string $subject) Set the subject of the Message
string getSubject() Retrieve the subject of the Message
$this setBodyAndPlainText(string $body) Set the Message body. Providing HTML will set both HTML and Plain-Text
$this setBody(string $body) Set the HTML body of the Message
$this setBodyFromSmarty(string $body) Set the Message body from a parsed Smarty template
string getBody() Retrieve the HTML body of the Message
string getBodyWithoutCSS() Retrieve the HTML body of the Message without Global CSS included
$this setPlainText(string $text) Set the Plain-Text body of the Message
string replaceLinksWithUrl(string $text) Replace links for the plain text version with just the href
string getPlainText() Retrieve the Plain-Text body of the Message
$this addStringAttachment(string $filename, string $data) Add string attachment
$this addFileAttachment(string $filename, string $filepath) deprecated Add attachment from file system
array getAttachments() Retrieve attachments for the Message
array getAttachmentNames() Retrieve the filenames for attachments associated with the Message
bool hasRecipients() Check if the Message has at least one recipient defined
int saveToEmailLog(int $userId) Save the Message to the Email Log
setGlobalBCCRecipients() -
Message setEmailHeadersForType(string $type = '') -
Message setHeader(string $name, string $value = '') -
array getHeaders() -

Details

__construct ()

$this setEmailLogId ($id)

Set the ID of the email relative to tblemails.id

Parameters

$id

Return Value

$this

static Message createFromTemplate (Template $template)

Build an Email Message from a predefined Template

Parameters

Template $template

Return Value

Message

Exceptions

InvalidTemplate When attachment is missing

$this setType (string $type)

Set the Email Type. e.g. 'general'

Parameters

string $type

Return Value

$this

string getType ()

Retrieve the Message type

Return Value

string

$this setTemplateName (string $templateName)

Set the Message template name

Parameters

string $templateName

Return Value

$this

string getTemplateName ()

Retrieve the Message template name

Return Value

string

$this addRecipient (string $kind, string $email, string $name = '')

Add a recipient for the Message

Parameters

string $kind Either 'to', 'cc' or 'bcc'
string $email Recipient Email Address
string $name Recipient Name

Return Value

$this

$this clearRecipients (string $kind)

Clear recipients for a specific kind

Parameters

string $kind Either 'to', 'cc' or 'bcc'

Return Value

$this

$this setFromName (string $name)

Set the "From" name for the Message

Parameters

string $name

Return Value

$this

string getFromName ()

Retrieve the "From" name for the message

Return Value

string

$this setFromEmail (string $email)

Set the sender Email Address for the Message

Parameters

string $email

Return Value

$this

mixed getFromEmail ()

Retrieve the sender Email Address for the Message

Return Value

mixed

string getFormattedFrom ()

Retrieve the sender Email Address and Name formatted for sending. e.g. 'John Doejohn@example.net'

Return Value

string

$this setReplyTo (string $email, string $name = '')

Set the Reply To address and name for the Message

Parameters

string $email
string $name

Return Value

$this

array getReplyTo ()

Retrieve the Reply To address and name for the Message

Return Value

array

getReplyToName ()

getReplyToEmail ()

string getFormattedReplyTo ()

Retrieve the reply-to Email Address and Name formatted for sending. e.g. 'John Doejohn@example.net'

Return Value

string

array getRecipients (string $kind)

Retrieve the recipients for the Message

Parameters

string $kind Either 'to', 'cc' or 'bcc'

Return Value

array

array|string getFormattedRecipients ($kind)

Retrieve the sender Email Addresses and Names formatted for sending. e.g. 'John Doe john@example.net'

Parameters

$kind

Return Value

array|string Recipients if set and an empty string if no recipients are specified

$this setSubject (string $subject)

Set the subject of the Message

Parameters

string $subject

Return Value

$this

string getSubject ()

Retrieve the subject of the Message

Return Value

string

$this setBodyAndPlainText (string $body)

Set the Message body. Providing HTML will set both HTML and Plain-Text

Parameters

string $body

Return Value

$this

$this setBody (string $body)

Set the HTML body of the Message

Parameters

string $body

Return Value

$this

$this setBodyFromSmarty (string $body)

Set the Message body from a parsed Smarty template

Parameters

string $body

Return Value

$this

string getBody ()

Retrieve the HTML body of the Message

Return Value

string

string getBodyWithoutCSS ()

Retrieve the HTML body of the Message without Global CSS included

Return Value

string

$this setPlainText (string $text)

Set the Plain-Text body of the Message

Parameters

string $text

Return Value

$this

protected string replaceLinksWithUrl (string $text)

Replace links for the plain text version with just the href

Parameters

string $text Text to transform into a clickable link

Return Value

string

string getPlainText ()

Retrieve the Plain-Text body of the Message

Return Value

string

$this addStringAttachment (string $filename, string $data)

Add string attachment

Parameters

string $filename The name of the attachment
string $data The attachment data

Return Value

$this

$this addFileAttachment (string $filename, string $filepath) deprecated

deprecated Use with care - attachments are no longer necessarily stored locally

Add attachment from file system

Parameters

string $filename The name of the file
string $filepath The path to the file

Return Value

$this

array getAttachments ()

Retrieve attachments for the Message

Return Value

array

array getAttachmentNames ()

Retrieve the filenames for attachments associated with the Message

Return Value

array

bool hasRecipients ()

Check if the Message has at least one recipient defined

Return Value

bool

int saveToEmailLog (int $userId)

Save the Message to the Email Log

Parameters

int $userId The User ID receiving the Message

Return Value

int Email Log Entry ID

protected setGlobalBCCRecipients ()

protected Message setEmailHeadersForType (string $type = '')

Parameters

string $type

Return Value

Message

Message setHeader (string $name, string $value = '')

Parameters

string $name
string $value

Return Value

Message

array getHeaders ()

Return Value

array