Mail
in package
Uses
BackwardCompatibility
Class for preparing and handling email messages.
Table of Contents
Properties
- $backcompat : array<string|int, mixed>
Methods
- addToQueue() : bool
- Add an email to the mail queue.
- adminNotify() : mixed
- This simple function gets a list of all administrators and sends them an email to let them know a new member has joined.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- loadEmailTemplate() : array<string|int, mixed>
- Load a template from EmailTemplates language file.
- mimespecialchars() : array<string|int, mixed>
- Prepare text strings for sending as email body or header.
- reduceQueue() : bool
- Send a group of emails from the mail queue.
- send() : bool
- This function sends an email to the specified recipient(s).
- sendNotifications() : mixed
- Sends a notification to members who have elected to receive emails when things happen to a topic, such as replies are posted.
- userInfoCallback() : string
- Callback function for loadEmailTemplate on subject and body Uses capture group 1 in array
Properties
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['send' => 'sendmail', 'addToQueue' => 'AddMailQueue', 'reduceQueue' => 'reduceQueue', 'mimespecialchars' => 'mimespecialchars', 'sendSmtp' => 'smtp_mail', 'serverParse' => 'serverParse', 'sendNotifications' => 'sendNotifications', 'adminNotify' => 'adminNotify', 'loadEmailTemplate' => 'loadEmailTemplate']]
BackwardCompatibility settings for this class.
Methods
addToQueue()
Add an email to the mail queue.
public
static addToQueue([bool $flush = false ][, array<string|int, mixed> $to_array = [] ][, string $subject = '' ][, string $message = '' ][, string $headers = '' ][, bool $send_html = false ][, int $priority = 3 ][, bool $is_private = false ]) : bool
Parameters
- $flush : bool = false
-
Whether to flush the queue
- $to_array : array<string|int, mixed> = []
-
An array of recipients
- $subject : string = ''
-
The subject of the message
- $message : string = ''
-
The message
- $headers : string = ''
-
The headers
- $send_html : bool = false
-
Whether to send in HTML format
- $priority : int = 3
-
The priority
- $is_private : bool = false
-
Whether this is private
Return values
bool —Whether the message was added
adminNotify()
This simple function gets a list of all administrators and sends them an email to let them know a new member has joined.
public
static adminNotify(string $type, int $memberID[, string $member_name = null ]) : mixed
Called by registerMember() function in Subs-Members.php. Email is sent to all groups that have the moderate_forum permission. The language set by each member is being used (if available). Uses the Login language file
Parameters
- $type : string
-
The type. Types supported are 'approval', 'activation', and 'standard'.
- $memberID : int
-
The ID of the member
- $member_name : string = null
-
The name of the member (if null, it is pulled from the database)
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
loadEmailTemplate()
Load a template from EmailTemplates language file.
public
static loadEmailTemplate(string $template[, array<string|int, mixed> $replacements = [] ][, string $lang = '' ][, bool $loadLang = true ]) : array<string|int, mixed>
Parameters
- $template : string
-
The name of the template to load
- $replacements : array<string|int, mixed> = []
-
An array of replacements for the variables in the template
- $lang : string = ''
-
The language to use, if different than the user's current language
- $loadLang : bool = true
-
Whether to load the language file first
Return values
array<string|int, mixed> —An array containing the subject and body of the email template, with replacements made
mimespecialchars()
Prepare text strings for sending as email body or header.
public
static mimespecialchars(string $string[, bool $with_charset = true ][, bool $hotmail_fix = false ][, string $line_break = "
" ][, string $custom_charset = null ]) : array<string|int, mixed>
In case there are higher ASCII characters in the given string, this function will attempt the transport method 'quoted-printable'. Otherwise the transport method '7bit' is used.
Parameters
- $string : string
-
The string
- $with_charset : bool = true
-
Whether we're specifying a charset ($custom_charset must be set here)
- $hotmail_fix : bool = false
-
Whether to apply the hotmail fix (all higher ASCII characters are converted to HTML entities to assure proper display of the mail)
- $line_break : string = " "
-
The linebreak
- $custom_charset : string = null
-
If set, it uses this character set
Return values
array<string|int, mixed> —An array containing the character set, the converted string and the transport method.
reduceQueue()
Send a group of emails from the mail queue.
public
static reduceQueue([bool|int $number = false ][, bool $override_limit = false ][, bool $force_send = false ]) : bool
Parameters
- $number : bool|int = false
-
The number to send each loop through or false to use the standard limits
- $override_limit : bool = false
-
Whether to bypass the limit
- $force_send : bool = false
-
Whether to forcibly send the messages now (useful when using cron jobs)
Return values
bool —Whether things were sent
send()
This function sends an email to the specified recipient(s).
public
static send(array<string|int, mixed> $to, string $subject, string $message[, string $from = null ][, string $message_id = null ][, bool $send_html = false ][, int $priority = 3 ][, bool $hotmail_fix = null ][, bool $is_private = false ]) : bool
It uses the mail_type settings and webmaster_email variable.
Parameters
- $to : array<string|int, mixed>
-
The email(s) to send to
- $subject : string
-
Email subject, expected to have entities, and slashes, but not be parsed
- $message : string
-
Email body, expected to have slashes, no htmlentities
- $from : string = null
-
The address to use for replies
- $message_id : string = null
-
If specified, it will be used as local part of the Message-ID header.
- $send_html : bool = false
-
Whether or not the message is HTML vs. plain text
- $priority : int = 3
-
The priority of the message
- $hotmail_fix : bool = null
-
Whether to apply the "hotmail fix"
- $is_private : bool = false
-
Whether this is private
Return values
bool —Whether ot not the email was sent properly.
sendNotifications()
Sends a notification to members who have elected to receive emails when things happen to a topic, such as replies are posted.
public
static sendNotifications(array<string|int, mixed> $topics, string $type[, array<string|int, mixed> $exclude = [] ][, array<string|int, mixed> $members_only = [] ]) : mixed
The function automatically finds the subject and its board, and checks permissions for each member who is "signed up" for notifications. It will not send 'reply' notifications more than once in a row. Uses Post language file
Parameters
- $topics : array<string|int, mixed>
-
Represents the topics the action is happening to.
- $type : string
-
Can be any of reply, sticky, lock, unlock, remove, move, merge, and split. An appropriate message will be sent for each.
- $exclude : array<string|int, mixed> = []
-
Members in the exclude array will not be processed for the topic with the same key.
- $members_only : array<string|int, mixed> = []
-
Are the only ones that will be sent the notification if they have it on.
userInfoCallback()
Callback function for loadEmailTemplate on subject and body Uses capture group 1 in array
protected
static userInfoCallback(array<string|int, mixed> $matches) : string
Parameters
- $matches : array<string|int, mixed>
-
An array of matches
Return values
string —The match