IEMailTemplate
in
Interface IEMailTemplate
Interface to a class that allows to build HTML emails
Example:
defaults, $this->urlGenerator, $this->l10n); $emailTemplate->addHeader(); $emailTemplate->addHeading('Welcome aboard'); $emailTemplate->addBodyText('Welcome to your Nextcloud account, you can add, protect, and share your data.'); $emailTemplate->addBodyButtonGroup( 'Set your password', 'https://example.org/resetPassword/q1234567890qwertz', 'Install Client', 'https://nextcloud.com/install/#install-clients' ); $emailTemplate->addFooter('Optional footer text'); $htmlContent = $emailTemplate->renderHtml(); $plainContent = $emailTemplate->renderText();Tags
Table of Contents
Constants
- NOTE_ERROR : mixed = 'error'
- NOTE_INFO : mixed = 'info'
- NOTE_NEUTRAL : mixed = 'neutral'
- Note for content written by a user, e.g. a share note
- NOTE_WARNING : mixed = 'warning'
Methods
- addBodyButton() : mixed
- Adds a button to the body of the email
- addBodyButtonGroup() : mixed
- Adds a button group of two buttons to the body of the email
- addBodyButtons() : void
- Adds a row of buttons to the body of the email, the first one is the primary action
- addBodyDetails() : void
- Adds a card with a title and labelled rows to the body of the email
- addBodyListItem() : mixed
- Adds a list item to the body of the email
- addBodyNote() : void
- Adds a highlighted box to the body of the email
- addBodySender() : void
- Adds the person an email is about (sharer, organizer...), shown with an initials circle
- addBodyText() : mixed
- Adds a paragraph to the body of the email
- addFooter() : mixed
- Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
- addHeader() : mixed
- Adds a header to the email
- addHeading() : mixed
- Adds a heading to the email
- renderHtml() : string
- Returns the rendered HTML email as string
- renderSubject() : string
- Returns the rendered email subject as string
- renderText() : string
- Returns the rendered plain text email as string
- setLanguage() : void
- Sets the language of the recipient
- setSubject() : mixed
- Sets the subject of the email
Constants
NOTE_ERROR
public
mixed
NOTE_ERROR
= 'error'
Tags
NOTE_INFO
public
mixed
NOTE_INFO
= 'info'
Tags
NOTE_NEUTRAL
Note for content written by a user, e.g. a share note
public
mixed
NOTE_NEUTRAL
= 'neutral'
Tags
NOTE_WARNING
public
mixed
NOTE_WARNING
= 'warning'
Tags
Methods
addBodyButton()
Adds a button to the body of the email
public
addBodyButton(string $text, string $url[, string|false $plainText = '' ]) : mixed
Parameters
- $text : string
-
Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
- $url : string
-
URL of button
- $plainText : string|false = ''
-
Text of button in plain text version if empty the $text is used, if false none will be used
Tags
addBodyButtonGroup()
Adds a button group of two buttons to the body of the email
public
addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight[, string $plainTextLeft = '' ][, string $plainTextRight = '' ]) : mixed
Parameters
- $textLeft : string
-
Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
- $urlLeft : string
-
URL of left button
- $textRight : string
-
Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
- $urlRight : string
-
URL of right button
- $plainTextLeft : string = ''
-
Text of left button that is used in the plain text version - if empty the $textLeft is used
- $plainTextRight : string = ''
-
Text of right button that is used in the plain text version - if empty the $textRight is used
Tags
addBodyButtons()
Adds a row of buttons to the body of the email, the first one is the primary action
public
addBodyButtons(array<int, array{text: string, url: string}> $buttons[, string $label = '' ]) : void
Parameters
- $buttons : array<int, array{text: string, url: string}>
- $label : string = ''
-
Optional text shown above the buttons, e.g. "Will you attend?"
Tags
addBodyDetails()
Adds a card with a title and labelled rows to the body of the email
public
addBodyDetails(EMailDetails $details) : void
Parameters
- $details : EMailDetails
Tags
addBodyListItem()
Adds a list item to the body of the email
public
addBodyListItem(string $text[, string $metaInfo = '' ][, string $icon = '' ][, string|bool $plainText = '' ][, string|bool $plainMetaInfo = '' ][, mixed $plainIndent = 0 ]) : mixed
Parameters
- $text : string
-
; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
- $metaInfo : string = ''
-
; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
- $icon : string = ''
-
Absolute path, must be 16*16 pixels
- $plainText : string|bool = ''
-
Text that is used in the plain text email if empty the $text is used, if false none will be used
- $plainMetaInfo : string|bool = ''
-
Meta info that is used in the plain text email if empty the $metaInfo is used, if false none will be used
- $plainIndent : mixed = 0
Tags
addBodyNote()
Adds a highlighted box to the body of the email
public
addBodyNote(string $text[, string $label = '' ][, self::NOTE_* $type = self::NOTE_NEUTRAL ]) : void
Use self::NOTE_NEUTRAL for content written by a user (share note, event description), the other types for messages from the server itself. Line breaks in $text are kept. A short note about a shared item goes before its details card, longer content like an event description after it.
Parameters
- $text : string
- $label : string = ''
-
Label above the text for neutral notes, bold title before it for the other types
- $type : self::NOTE_* = self::NOTE_NEUTRAL
Tags
addBodySender()
Adds the person an email is about (sharer, organizer...), shown with an initials circle
public
addBodySender(string $displayName[, string $subline = '' ]) : void
Parameters
- $displayName : string
- $subline : string = ''
-
Optional second line, e.g. the email address
Tags
addBodyText()
Adds a paragraph to the body of the email
public
addBodyText(string $text[, string|bool $plainText = '' ]) : mixed
Parameters
- $text : string
-
; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
- $plainText : string|bool = ''
-
Text that is used in the plain text email if empty the $text is used, if false none will be used
Tags
addFooter()
Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
public
addFooter([string $text = '' ][, string $lang = null ]) : mixed
Parameters
- $text : string = ''
-
If the text is empty the default "Name - Slogan
This is an automatically sent email" will be used - $lang : string = null
-
Optional language to set the default footer in
Tags
addHeader()
Adds a header to the email
public
addHeader() : mixed
Tags
addHeading()
Adds a heading to the email
public
addHeading(string $title[, string|bool $plainTitle = '' ]) : mixed
Parameters
- $title : string
- $plainTitle : string|bool = ''
-
Title that is used in the plain text email if empty the $title is used, if false none will be used
Tags
renderHtml()
Returns the rendered HTML email as string
public
renderHtml() : string
Tags
Return values
stringrenderSubject()
Returns the rendered email subject as string
public
renderSubject() : string
Tags
Return values
stringrenderText()
Returns the rendered plain text email as string
public
renderText() : string
Tags
Return values
stringsetLanguage()
Sets the language of the recipient
public
setLanguage(string $language) : void
Used for the lang and dir attributes of the HTML email, mirrors the layout for right-to-left languages, and is the default language of the footer. Call it before addFooter().
Parameters
- $language : string
-
Language code, e.g.
arorpt_BR
Tags
setSubject()
Sets the subject of the email
public
setSubject(string $subject) : mixed
Parameters
- $subject : string