Class
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.
| Name | Description |
|---|---|
HEADER_MARKER | |
FOOTER_MARKER | |
RFC3834_HEADERS | |
RECIPIENT_TYPES |
public function __construct()public function setEmailLogId($id)Set the ID of the email relative to tblemails.id
Returns $this
public static function createFromTemplate(Template $template)Build an Email Message from a predefined Template
Parameters
| Type | Name | Description |
|---|---|---|
Template | $template |
Returns Message
public function setType($type)Set the Email Type. e.g. 'general'
Parameters
| Type | Name | Description |
|---|---|---|
string | $type |
Returns $this
public function getType()Retrieve the Message type
Returns string
public function setTemplateName($templateName)Set the Message template name
Parameters
| Type | Name | Description |
|---|---|---|
string | $templateName |
Returns $this
public function getTemplateName()Retrieve the Message template name
Returns string
public function addRecipient(string $type, string $email, string $name = '')Add a recipient for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $type | Either 'to', 'cc' or 'bcc' |
string | $email | Recipient Email Address are normalized (lower-cased) |
string | $name | Recipient Name |
Returns $this
public function getAllRecipients(): arraypublic function hasRecipientByEmail($email): boolpublic function clearRecipients($type)Clear recipients for a specific kind
Parameters
| Type | Name | Description |
|---|---|---|
string | $type | Either 'to', 'cc' or 'bcc' |
Returns $this
public function setFromName($name)Set the "From" name for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $name |
Returns $this
public function getFromName()Retrieve the "From" name for the message
Returns string
public function setFromEmail($email)Set the sender Email Address for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $email |
Returns $this
public function getFromEmail()Retrieve the sender Email Address for the Message
Returns mixed
public function getFormattedFrom()Retrieve the sender Email Address and Name formatted for sending. e.g. 'John Doe<[email protected]>'
Returns string
public function setReplyTo($email, $name = '')Set the Reply To address and name for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $email | |
string | $name |
Returns $this
public function getReplyTo()Retrieve the Reply To address and name for the Message
Returns array
public function getReplyToName()public function getReplyToEmail()public function getFormattedReplyTo(): stringRetrieve the reply-to Email Address and Name formatted for sending. e.g. 'John Doe<[email protected]>'
Returns string
public function getRecipients($type)Retrieve the recipients for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $type | Either 'to', 'cc' or 'bcc' |
Returns array
public function getRecipientsEmailAddress($type)Retrieve the recipients email addresses for the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $type | Either 'to', 'cc' or 'bcc' |
Returns string[]
public function getFormattedRecipients(string $type = null): arrayRetrieve the Email Addresses and Names formatted for sending. e.g. 'John Doe <[email protected]>'
Parameters
| Type | Name | Description |
|---|---|---|
string|null | $type | If $type is null, recipients across all types will be returned. Otherwise, only recipients for the provided $type |
Returns array — Recipients or an empty array if no recipients are present
public function setSubject($subject)Set the subject of the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $subject |
Returns $this
public function getSubject()Retrieve the subject of the Message
Returns string
public function setBodyAndPlainText($body)Set the Message body. Providing HTML will set both HTML and Plain-Text
Parameters
| Type | Name | Description |
|---|---|---|
string | $body |
Returns $this
public function setBody($body)Set the HTML body of the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $body |
Returns $this
public function applyGlobalWrapper(string $blob): stringIf defined and not already present, wrap $blob in any header and/or footer defined by global settings.
Parameters
| Type | Name | Description |
|---|---|---|
string | $blob |
Returns string
public function appendGlobalHeader(string $blob): stringIf defined and not already present, wrap $blob in any header defined by global settings.
Parameters
| Type | Name | Description |
|---|---|---|
string | $blob |
Returns string
public function appendGlobalFooter(string $blob): stringIf defined and not already present, wrap $blob in any footer defined by global settings.
Parameters
| Type | Name | Description |
|---|---|---|
string | $blob |
Returns string
public function setBodyFromSmarty($body)Set the Message body from a parsed Smarty template
Parameters
| Type | Name | Description |
|---|---|---|
string | $body |
Returns $this
public function getBody()Retrieve the HTML body of the Message
Returns string
public function getBodyWithoutCSS()Retrieve the HTML body of the Message without Global CSS included
Returns string
public function setPlainText($text)Set the Plain-Text body of the Message
Parameters
| Type | Name | Description |
|---|---|---|
string | $text |
Returns $this
public function getPlainText()Retrieve the Plain-Text body of the Message
Returns string
public function addStringAttachment($filename, $data)Add string attachment
Parameters
| Type | Name | Description |
|---|---|---|
string | $filename | The name of the attachment |
string | $data | The attachment data |
Returns $this
public function addFileAttachment($filename, $filepath)Add attachment from file system
Parameters
| Type | Name | Description |
|---|---|---|
string | $filename | The name of the file |
string | $filepath | The path to the file |
Returns $this
public function getAttachments()Retrieve attachments for the Message
Returns array
public function getAttachmentNames(): arrayRetrieve the filenames for attachments associated with the Message
Returns array
public function hasRecipients()Check if the Message has at least one recipient defined
Returns bool
public function saveToEmailLog(int $userId)Save the Message to the Email Log
Parameters
| Type | Name | Description |
|---|---|---|
int | $userId | The User ID receiving the Message |
Returns int — Email Log Entry ID
public function setHeader(string $name, string $value = ''): selfpublic function getHeaders(): array