Email
in package
Class for creating and sending emails.
Tags
Table of Contents
Constants
- MAIL_DEFAULTS = array('to' => '', 'cc' => '', 'bcc' => '', 'subject' => 'email', 'body' => '', 'headers' => array(), 'attachments' => array(), 'is_internal' => false)
- The array of default arguments for the email.
Properties
- $attachments : array<string|int, string>
- The email attachments.
- $bcc : array<string|int, string>
- The bcc recipients of the email.
- $cc : array<string|int, string>
- The cc recipients of the email.
- $headers : array<string|int, string>
- The email headers.
- $is_internal : bool
- The internal/external email flag.
- $message : string
- The email message.
- $subject : string
- The subject of the email.
- $to : array<string|int, string>
- The recipients of the email.
Methods
- __construct() : void
- Initialise the class and set its properties.
- get_message() : string
- Return the email message body.
- get_parameters() : array<string|int, mixed>
- Return the complete email parameters.
- send() : bool|WP_Error
- Checks for minimum requirements then sends the email.
- sanitise_email_array() : array<string|int, mixed>
- Sanitise an array of email addresses.
- set_attachments() : void|WP_Error
- Attach a file or array of files.
- set_bcc() : void
- Set bcc recipients.
- set_cc() : void
- Set cc recipients.
- set_headers() : void
- Set the email headers.
- set_is_internal() : void
- Set internal/external email flag.
- set_message() : void
- Set the message.
- set_partial_paths() : void
- Set fully qualified paths to required partials.
- set_subject() : void
- Set subject.
- set_to() : void
- Set recipients.
Constants
MAIL_DEFAULTS
The array of default arguments for the email.
protected
mixed
MAIL_DEFAULTS
= array('to' => '', 'cc' => '', 'bcc' => '', 'subject' => 'email', 'body' => '', 'headers' => array(), 'attachments' => array(), 'is_internal' => false)
Tags
Properties
$attachments
The email attachments.
protected
array<string|int, string>
$attachments
= array()
Tags
$bcc
The bcc recipients of the email.
protected
array<string|int, string>
$bcc
= array()
Tags
$cc
The cc recipients of the email.
protected
array<string|int, string>
$cc
= array()
Tags
$headers
The email headers.
protected
array<string|int, string>
$headers
= array()
Tags
$is_internal
The internal/external email flag.
protected
bool
$is_internal
= false
Tags
$message
The email message.
protected
string
$message
= ''
Tags
$subject
The subject of the email.
protected
string
$subject
= ''
Tags
$to
The recipients of the email.
protected
array<string|int, string>
$to
= array()
Tags
Methods
__construct()
Initialise the class and set its properties.
public
__construct(array<string|int, mixed> $args) : void
Parameters
- $args : array<string|int, mixed>
-
{ Array of email arguments. @type string|array $to The intended recipients. @type string|array $cc The copy recipients. @type string|array $bcc The blind copy recipients. @type string $subject The subject of the email. @type string $body The body content of the email. @type array $headers The email headers. @type array $attachments The files to attach to the email. @type bool $is_internal Flag to indicate that email is internal and not intended for external users. }
Tags
get_message()
Return the email message body.
public
get_message() : string
Tags
Return values
string —The email message body.
get_parameters()
Return the complete email parameters.
public
get_parameters() : array<string|int, mixed>
This inludes all the fields necessary for wp_mail.
Tags
Return values
array<string|int, mixed> —The email parameters .
send()
Checks for minimum requirements then sends the email.
public
send() : bool|WP_Error
Requires the email to have:
- recipient addresses(es).
- a subject.
- a message body
Tags
Return values
bool|WP_Errorsanitise_email_array()
Sanitise an array of email addresses.
protected
sanitise_email_array(array<string|int, mixed> $addresses) : array<string|int, mixed>
Parameters
- $addresses : array<string|int, mixed>
-
An array of email addresses.
Tags
Return values
array<string|int, mixed> —Cleaned email addresses.
set_attachments()
Attach a file or array of files.
protected
set_attachments(array<string|int, mixed> $attachments) : void|WP_Error
Parameters
- $attachments : array<string|int, mixed>
-
The absolute path(s) to the attachments to include with the email.
Tags
Return values
void|WP_Errorset_bcc()
Set bcc recipients.
protected
set_bcc(string|array<string|int, mixed> $bcc) : void
Parameters
- $bcc : string|array<string|int, mixed>
-
Intended bcc recipients of the email.
Tags
set_cc()
Set cc recipients.
protected
set_cc(string|array<string|int, mixed> $cc) : void
Parameters
- $cc : string|array<string|int, mixed>
-
Intended cc recipients of the email.
Tags
set_headers()
Set the email headers.
protected
set_headers(array<string|int, mixed> $headers) : void
Parameters
- $headers : array<string|int, mixed>
-
The email headers.
Tags
set_is_internal()
Set internal/external email flag.
protected
set_is_internal(bool $is_internal) : void
Parameters
- $is_internal : bool
-
Flag to set internal/external email recipients.
Tags
set_message()
Set the message.
protected
set_message(string $body) : void
Override this in subclasses to set message content.
Parameters
- $body : string
-
The body content of the email.
Tags
set_partial_paths()
Set fully qualified paths to required partials.
protected
set_partial_paths() : void
Override this function in sub-classes to set file paths without using constructor.
Tags
set_subject()
Set subject.
protected
set_subject(string $subject) : void
Parameters
- $subject : string
-
The subject of the email.
Tags
set_to()
Set recipients.
protected
set_to(string|array<string|int, mixed> $to) : void
Parameters
- $to : string|array<string|int, mixed>
-
Intended recipients of the email.