MailUtility
Class to handle mail specific functionality
Table of Contents
Methods
- breakLinesForEmail() : string
- Breaks up a single line of text for emails Words - longer than $lineWidth - will not be split into parts
- getSystemFrom() : array<string|int, string>|null
- Gets a valid "from" for mail messages (email and name).
- getSystemFromAddress() : string
- Creates a valid email address for the sender of mail messages.
- getSystemFromName() : string|null
- Creates a valid "from" name for mail messages.
- getSystemReplyTo() : array<string|int, string>
- Gets a default "reply-to" for mail messages (email and name).
- parseAddresses() : array<string|int, mixed>
- Parses mailbox headers and turns them into an array.
Methods
breakLinesForEmail()
Breaks up a single line of text for emails Words - longer than $lineWidth - will not be split into parts
public
static breakLinesForEmail(string $str[, string $newlineChar = LF ][, int $lineWidth = 76 ]) : string
Parameters
- $str : string
-
The string to break up
- $newlineChar : string = LF
-
The string to implode the broken lines with (default/typically \n)
- $lineWidth : int = 76
-
The line width
Return values
string —Reformatted text
getSystemFrom()
Gets a valid "from" for mail messages (email and name).
public
static getSystemFrom() : array<string|int, string>|null
Ready to be passed to $mail->setFrom()
This method can return three different variants:
- An assoc. array: key => Valid email address which can be used as sender; value => Valid name which can be used as a sender
- A numeric array with one entry: Valid email address which can be used as sender
- Null, if no address is configured
Return values
array<string|int, string>|nullgetSystemFromAddress()
Creates a valid email address for the sender of mail messages.
public
static getSystemFromAddress() : string
Uses a fallback chain: $TYPO3_CONF_VARS['MAIL']['defaultMailFromAddress'] -> no-reply@FirstDomainRecordFound -> no-reply@php_uname('n') -> no-reply@example.com
Ready to be passed to $mail->setFrom()
Return values
string —An email address
getSystemFromName()
Creates a valid "from" name for mail messages.
public
static getSystemFromName() : string|null
As configured in Install Tool.
Return values
string|null —The name (unquoted, unformatted). NULL if none is set or an invalid non-string value.
getSystemReplyTo()
Gets a default "reply-to" for mail messages (email and name).
public
static getSystemReplyTo() : array<string|int, string>
Ready to be passed to $mail->setReplyTo()
This method returns a list of email addresses, but depending on the existence of "defaultMailReplyToName" the array can have a different shape:
- An assoc. array: key => a valid reply-to address which can be used as sender; value => a valid reply-to name which can be used as a sender
- A numeric array with one entry: a valid reply-to address which can be used as sender
Return values
array<string|int, string>parseAddresses()
Parses mailbox headers and turns them into an array.
public
static parseAddresses(string $rawAddresses) : array<string|int, mixed>
Mailbox headers are a comma separated list of 'name email@example.org' combinations or plain email addresses (or a mix of these). The resulting array has key-value pairs where the key is either a number (no display name in the mailbox header) and the value is the email address, or the key is the email address and the value is the display name.
Parameters
- $rawAddresses : string
-
Comma separated list of email addresses (optionally with display name)
Return values
array<string|int, mixed> —Parsed list of addresses.