Class to manage preparing and sending emails.

This sends plain text and HTML emails.

package XenForo_Mail

 Methods

Constructor.

__construct(string $emailTitle, array $params, integer | null $languageId) 

Parameters

$emailTitle

string

Title of the email template

$params

array

Key-value params to pass to email template

$languageId

integernull

Language of email; if null, uses language of current user (if setup)

Factory.

create(string $emailTitle, array $params, integer | null $languageId) : \XenForo_Mail

Parameters

$emailTitle

string

Title of the email template

$params

array

Key-value params to pass to email template

$languageId

integernull

Language of email; if null, uses language of current user (if setup)

Returns

Enables pre-caching of this email template in all languages.

enableAllLanguagePreCache() 

This will only apply if the email template needs to be loaded.

Gets the default mail transport object.

getDefaultTransport() : \Zend_Mail_Transport_Abstract

Returns

\Zend_Mail_Transport_Abstract

Gets the failure exception if there is one.

getFailureException() : \Exception | null

Returns

Gets the fully prepared, internal mail object.

getPreparedMailHandler(string $toEmail, string $toName, array $headers, string $fromEmail, string $fromName, string $returnPath) : \Zend_Mail | false

This can be called directly to allow advanced manipulation before sending

Parameters

$toEmail

string

The email address the email is sent to

$toName

string

Name of the person receiving it

$headers

array

List of additional headers to send

$fromEmail

string

Email address the email should come from; if not specified, uses board default

$fromName

string

Name the email should come from; if not specified, uses board default

$returnPath

string

The return path of the email (where bounces should go to)

Returns

\Zend_Mailfalse

Prepares the subject, plain text body, and HTML body.

prepareMailContents(string | null $emailTitle, array $params) : array | false

Parameters

$emailTitle

stringnull

Title of email to send. If not specified, uses value from consructor.

$params

arraynull

Params to pass to email template. If not specified, uses value from constructor.

Returns

arrayfalseFalse if the template can't be found; otherwise array with subject, bodyText, and bodyHtml keys

Prepares an email for sending, but places it in a queue for sending later.

queue(string $toEmail, string $toName, array $headers, string $fromEmail, string $fromName, string $returnPath) : boolean

Parameters

$toEmail

string

The email address the email is sent to

$toName

string

Name of the person receiving it

$headers

array

List of additional headers to send

$fromEmail

string

Email address the email should come from; if not specified, uses board default

$fromName

string

Name the email should come from; if not specified, uses board default

$returnPath

string

The return path of the email (where bounces should go to)

Returns

booleanTrue on success

Reset the email cache.

resetEmailCache() 

The MAIL_CONTAINER will still be listed as pre-cacheable.

Sends the given email.

send(string $toEmail, string $toName, array $headers, string $fromEmail, string $fromName, string $returnPath) : boolean

Parameters

$toEmail

string

The email address the email is sent to

$toName

string

Name of the person receiving it

$headers

array

List of additional headers to send

$fromEmail

string

Email address the email should come from; if not specified, uses board default

$fromName

string

Name the email should come from; if not specified, uses board default

$returnPath

string

The return path of the email (where bounces should go to)

Returns

booleanTrue on success

Sends the given mail object.

sendMail(\Zend_Mail $mailObj) : boolean

The mail transport system will be setup first, if necessary.

Parameters

$mailObj

\Zend_Mail

Mail to send.

Returns

boolean

Sets a value in the email cache.

setEmailCache(string $emailTitle, integer $languageId, string $template) 

Parameters

$emailTitle

string

$languageId

integer

$template

string

Set up the default mail transport object.

setupTransport(\Zend_Mail_Transport_Abstract $transport) 

If no transport is given, the default is selected based on board configuration.

Parameters

$transport

\Zend_Mail_Transport_Abstractnull

If specified, used as default transport; otherwise, use board config

Wraps the mail container template around a given message.

wrapMailContainer(string $subject, string $bodyText, string $bodyHtml) : array

Parameters

$subject

string

$bodyText

string

$bodyHtml

string

Returns

arrayWrapped mail; keys: subject, bodyText, bodyHtml

Get the default sendmail (built-in PHP mail()) transport object, based on the configuration in the given array.

_getDefaultSendmailTransport(array $transportOption) : \Zend_Mail_Transport_Sendmail

Parameters

$transportOption

array

Deata from option (sendmailReturnPath, etc)

Returns

\Zend_Mail_Transport_Sendmail

Get the default SMTP mail tranport object, based on the configuration in the given array.

_getDefaultSmtpTransport(array $transportOption) : \Zend_Mail_Transport_Smtp

Parameters

$transportOption

array

Data from option (smtpPort, smtpAuth, etc)

Returns

\Zend_Mail_Transport_Smtp

Loads the specified email template from the cache or DB.

_loadEmailTemplate(string $emailTitle) : string

Parameters

$emailTitle

string

Returns

string

Loads all email templates that are to be pre-cached from the DB.

_loadEmailTemplatesFromDb() 

They will be placed on the local email cache.

 Properties

 

A cache of previously sent emails.

$_emailCache : array

 

The title of the email to be sent by this instance.

$_emailTitle : string

 

Captured exception when an email fails to send (at the transport level).

$_failureException : \Exception | null

 

$_headerMap

$_headerMap 

 

The language ID the email should be sent in.

$_languageId : integer

 

Parameters to pass to the email template.

$_params : array

 

List of email templates that need to be pre-cached.

$_preCache : array

 

Controls whether the phrase value for all languages should be pre-cached.

$_preCacheAllLanguages : boolean

This is useful when sending the same email to multiple users (eg, subscription notifications).

 

Stores whether or not the transport layer has been setup.

$_transportSetup : boolean

This is setup when the first mail is to be sent, but can be explicitly called if desired.