MailTemplate

Email Templating Class

since

4.0.0

package

Application

Methods

__construct

Constructor for the mail templating class

__construct(string templateId, string language, \Joomla\CMS\Mail\Mail mailer = null) : mixed
since

4.0.0

Arguments

templateId

stringId of the mail template.

language

stringLanguage of the template to use.

mailer

\Joomla\CMS\Mail\MailMail object to send the mail with.

Response

mixed

addAttachment

Add an attachment to the mail

addAttachment(string name, string file) : void
since

4.0.0

Arguments

name

stringFilename of the attachment

file

stringEither a filepath or filecontent

addRecipient

Adds recipients for this mail

addRecipient(string mail, string name = null, string type = 'to') : void
since

4.0.0

Arguments

mail

stringMail address of the recipient

name

stringName of the recipient

type

stringHow should the recipient receive the mail? ('to', 'cc', 'bcc')

addTemplateData

Add data to replace in the template

addTemplateData(array data) : void
since

4.0.0

Arguments

data

arrayAssociative array of strings to replace

createTemplate

Insert a new mail template into the system

createTemplate(string key, string subject, string body, array tags, string htmlbody = '') : bool
static
since

4.0.0

Arguments

key

stringMail template key

subject

stringA default subject (normally a translatable string)

body

stringA default body (normally a translatable string)

tags

arrayAssociative array of tags to replace

htmlbody

stringA default htmlbody (normally a translatable string)

Response

boolTrue on success, false on failure

deleteTemplate

Method to delete a mail template

deleteTemplate(string key) : bool
static
since

4.0.0

Arguments

key

stringThe key of the mail template

Response

boolTrue on success, false on failure

getAttachmentName

Check and if necessary fix the file name of an attachment so that the attached file has the same extension as the source file, and not a different file extension

getAttachmentName(string file, string name) : string
since

4.0.0

Arguments

file

stringPath to the file to be attached

name

stringThe file name to be used for the attachment

Response

stringThe corrected file name for the attachment

getTemplate

Get a specific mail template

getTemplate(string key, string language) : object|null
static
since

4.0.0

Arguments

key

stringTemplate identifier

language

stringLanguage code of the template

Response

object|nullAn object with the data of the mail, or null if the template not found in the db.

replaceTags

Replace tags with their values recursively

replaceTags(string text, array tags) : string
since

4.0.0

Arguments

text

stringThe template to process

tags

arrayAn associative array to replace in the template

Response

stringRendered mail template

send

Render and send the mail

send() : bool
since

4.0.0

throws

\Exception

\Joomla\CMS\Mail\Exception\MailDisabledException

\PHPMailer\PHPMailer\Exception

Response

boolTrue on success

setReplyTo

Set reply to for this mail

setReplyTo(string mail, string name = '') : void
since

4.0.0

Arguments

mail

stringMail address to reply to

name

stringName

updateTemplate

Update an existing mail template

updateTemplate(string key, string subject, string body, array tags, string htmlbody = '') : bool
static
since

4.0.0

Arguments

key

stringMail template key

subject

stringA default subject (normally a translatable string)

body

stringA default body (normally a translatable string)

tags

arrayAssociative array of tags to replace

htmlbody

stringA default htmlbody (normally a translatable string)

Response

boolTrue on success, false on failure

Properties

mailer

Mailer object to send the actual mail.

since

4.0.0

Type(s)

Mail

template_id

Identifier of the mail template.

since

4.0.0

Type(s)

string

language

Language of the mail template.

Type(s)

string

data

since

4.0.0

Type(s)

string[]

attachments

since

4.0.0

Type(s)

string[]

recipients

List of recipients of the email

since

4.0.0

Type(s)

stdClass[]

replyto

Reply To of the email

since

4.0.0

Type(s)

\stdClass