pfeifferNet

Email
in package

Class for creating and sending emails.

Tags
since
1.0.0
since
5.9.0

Refactor to provide better inheitance for HTML_Email

used-by
HTML_Email

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
since
5.5.0
type

array MAIL_DEFAULTS { @type string $to The email address(es) of the intended recipient of the email. @type string $cc The copy recipients. @type string $bcc The blind copy recipients. @type string $subject The subject of the email. @type string $body The email message body. @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. }

Properties

$attachments

The email attachments.

protected array<string|int, string> $attachments = array()
Tags
since
1.0.0

$bcc

The bcc recipients of the email.

protected array<string|int, string> $bcc = array()
Tags
since
1.0.0

$cc

The cc recipients of the email.

protected array<string|int, string> $cc = array()
Tags
since
1.0.0

$headers

The email headers.

protected array<string|int, string> $headers = array()
Tags
since
1.0.0

$is_internal

The internal/external email flag.

protected bool $is_internal = false
Tags
since
5.9.0

$message

The email message.

protected string $message = ''
Tags
since
1.0.0

$subject

The subject of the email.

protected string $subject = ''
Tags
since
1.0.0

$to

The recipients of the email.

protected array<string|int, string> $to = array()
Tags
since
1.0.0

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
since
1.0.0

get_message()

Return the email message body.

public get_message() : string
Tags
since
5.6.0
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
since
5.9.0
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
since
1.0.0
Return values
bool|WP_Error

sanitise_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
since
1.0.0
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
since
1.0.0
Return values
void|WP_Error

set_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
since
1.0.0

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
since
1.0.0

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
since
1.0.0

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
since
1.0.0

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
since
1.0.0
since
5.9.0

Better separation of incoming body and outgoing message.

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
since
1.0.0

set_subject()

Set subject.

protected set_subject(string $subject) : void
Parameters
$subject : string

The subject of the email.

Tags
since
1.0.0

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.

Tags
since
1.0.0

        
On this page

Search results