class MailerService

Supports E-mail infrastructure for this framework.

Constants

FRAMEWORK_LAYOUT_PATH

Path to framework's layouts.

FRAMEWORK_TEMPLATE_PATH

Path to framework's templates.

FRAMEWORK_STYLES_PATH

Path to framework styles.

LAYOUT_PATH

Path to user defined layouts.

STYLES_PATH

Path to user defined styles.

TEMPLATE_PATH

Path to user defined templates.

Properties

protected Mailer $mailer

Mailer object.

Methods

__construct()

Creates a new mailer.

static string
layoutPath(string|null $layoutPath = null)

Supports ability to use alternative layout paths.

void
mailLogger(string $status, string $to, string $subject, string $htmlBody, string|null $textBody = null, string|null $template = null, string|null $error = null, array|null $attachments = null)

Logs each attempt at sending an E-mail.

string
renderTemplateFile(string $path, array $data = [])

Renders template file.

bool
send(string $to, string $subject, string $htmlBody, string|null $template = null, array $attachments = [])

Sends a HTML E-mail.

bool
sendTemplate(string $to, string $subject, string $template, array $data, string|null $layout = null, array $attachments = [], string|null $layoutPath = null, string|null $templatePath = null, string|null $styles = null, string|null $stylesPath = null)

Generates E-mail using a specified template, layout, and/or css stylesheet.

bool
sendWithText(string $to, string $subject, string $htmlBody, string $textBody, string|null $template = null, array $attachments = [])

Sends a text E-mail.

string
template(string $view, array $data = [], string|null $layout = null, string|null $layoutPath = null, string $templatePath, string|null $styles = null, string|null $stylesPath = null)

Prepares E-mail content based on template to be sent.

static string
templatePath(string|null $templatePath = null)

Supports ability to use alternative template paths.

Details

at line 37
__construct()

Creates a new mailer.

at line 50
static protected string layoutPath(string|null $layoutPath = null)

Supports ability to use alternative layout paths.

Parameters

string|null $layoutPath

The path to the layout.

Return Value

string

If parameter is null then constant is used. Otherwise, the value of the parameter is used.

at line 67
protected void mailLogger(string $status, string $to, string $subject, string $htmlBody, string|null $textBody = null, string|null $template = null, string|null $error = null, array|null $attachments = null)

Logs each attempt at sending an E-mail.

Parameters

string $status

The status of the attempt to send E-mail.

string $to

he recipient.

string $subject

The E-mail's subject.

string $htmlBody

The E-mail's content

string|null $textBody

The E-mail's text content.

string|null $template

The name of the template.

string|null $error

Reported errors for a send attempt.

array|null $attachments

An array of attachments. Default value is empty array.

Return Value

void

at line 120
protected string renderTemplateFile(string $path, array $data = [])

Renders template file.

Parameters

string $path

Path to the template.

array $data

Any data that needs to be passed to the view.

Return Value

string

The template's content.

at line 137
bool send(string $to, string $subject, string $htmlBody, string|null $template = null, array $attachments = [])

Sends a HTML E-mail.

Parameters

string $to

The recipient.

string $subject

The E-mail's subject.

string $htmlBody

The E-mail's content.

string|null $template

The template if it exists.

array $attachments

An array of attachments. Default value is empty array.

Return Value

bool

True if sent, otherwise we return false.

at line 196
bool sendTemplate(string $to, string $subject, string $template, array $data, string|null $layout = null, array $attachments = [], string|null $layoutPath = null, string|null $templatePath = null, string|null $styles = null, string|null $stylesPath = null)

Generates E-mail using a specified template, layout, and/or css stylesheet.

Parameters

string $to

The recipient.

string $subject

The E-mail's subject.

string $template

The template if it exists.

array $data

Any data that the template uses.

string|null $layout

The layout if it exists.

array $attachments

An array containing information about attachments.

string|null $layoutPath

The path to the layout.

string|null $templatePath

The path to the template.

string|null $styles

Name of stylesheet file.

string|null $stylesPath

The path to the stylesheet.

Return Value

bool

True if sent, otherwise we return false.

at line 232
bool sendWithText(string $to, string $subject, string $htmlBody, string $textBody, string|null $template = null, array $attachments = [])

Sends a text E-mail.

Parameters

string $to

The recipient.

string $subject

The E-mail's subject.

string $htmlBody

The E-mail's HTML content.

string $textBody

The E-mail's text content.

string|null $template

The template if it exists.

array $attachments

An array of attachments. Default value is empty array.

Return Value

bool

True if sent, otherwise we return false.

at line 287
protected string template(string $view, array $data = [], string|null $layout = null, string|null $layoutPath = null, string $templatePath, string|null $styles = null, string|null $stylesPath = null)

Prepares E-mail content based on template to be sent.

Parameters

string $view

The name of the template.

array $data

Any data that the template uses.

string|null $layout

The layout if it exists.

string|null $layoutPath

The path to the layout.

string $templatePath

The path to the template.

string|null $styles

The name of styles file.

string|null $stylesPath

Either framework or custom location.

Return Value

string

The E-mail's contents.

at line 329
static protected string templatePath(string|null $templatePath = null)

Supports ability to use alternative template paths.

Parameters

string|null $templatePath

The path to the template.

Return Value

string

If parameter is null then constant is used. Otherwise, the value of the parameter is used.