MailTemplate

Email Templating Class

since

4.0.0

package

Joomla CMS

Methods

__construct

Constructor for the mail templating class

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

4.0.0

Arguments

templateId

stringId of the mail template.

language

stringLanguage of the template to use.

mailer

MailMail object to send the mail with.

Response

mixed

addAttachment

Add an attachment to the mail

addAttachment( name,  file) : 
since

4.0.0

Arguments

name

stringFilename of the attachment

file

stringEither a filepath or filecontent

Response

void

addRecipient

Adds recipients for this mail

addRecipient( mail,  name = null,  type = 'to') : 
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')

Response

void

addTemplateData

Add data to replace in the template

addTemplateData(mixed||string|int data,  plain = false) : 
since

4.0.0

Arguments

data

array<string|int, mixed>Associative array of strings to replace

plain

boolOnly use the data for plain-text emails.

Response

void

addUnsafeTags

Mark tags as unsafe to ensure escaping in HTML mails

addUnsafeTags(mixed||string|int tags) : 
since

5.1.3

Arguments

tags

array<string|int, mixed>Tag names

Response

void

createTemplate

Insert a new mail template into the system

createTemplate( key,  subject,  body, mixed||string|int tags,  htmlbody = '') : 
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

array<string|int, mixed>Associative 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( key) : 
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( file,  name) : 
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( key,  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( text, mixed||string|int tags,  isHtml = false) : 
since

4.0.0

Arguments

text

stringThe template to process

tags

array<string|int, mixed>An associative array to replace in the template

isHtml

boolIs the text an HTML text and requires escaping

Response

stringRendered mail template

send

Render and send the mail

send() : 
since

4.0.0

throws

Exception

MailDisabledException

Exception

Response

boolTrue on success

setReplyTo

Set reply to for this mail

setReplyTo( mail,  name = '') : 
since

4.0.0

Arguments

mail

stringMail address to reply to

name

stringName

Response

void

updateTemplate

Update an existing mail template

updateTemplate( key,  subject,  body, mixed||string|int tags,  htmlbody = '') : 
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

array<string|int, mixed>Associative 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)

array<string|int, string>

plain_data

since

5.1.0

Type(s)

array<string|int, string>

unsafe_tags

since

5.1.3

Type(s)

array<string|int, string>

attachments

since

4.0.0

Type(s)

array<string|int, string>

recipients

List of recipients of the email

since

4.0.0

Type(s)

array<string|int, stdClass>

replyto

Reply To of the email

since

4.0.0

Type(s)

stdClass