Mailer
in package
uses
Loggable
Mailer class for handling email sending through multiple providers (PHPMailer, SendGrid, Symfony Mailer)
Table of Contents
Properties
- $alertRecipients : array<string|int, mixed>|string
- $charset : string
- $devRecipients : array<string|int, mixed>|string
- $feedbackRecipients : array<string|int, mixed>|string
- $logger : object|null
- $mailerMethod : string
- $mailerMethodDefaults : array<string|int, mixed>
- $mailerSettings : array<string|int, mixed>
- $mailerType : string
- $orderRecipients : array<string|int, mixed>|string
- $sendGrid : SendGrid|null
- $shopDomain : string
- $shopEnvironment : string
- $shopSettings : array<string|int, mixed>
- $symfony : Mailer|null
- $testRecipients : array<string|int, mixed>|string
- $wordWrap : int
Methods
- __construct() : mixed
- Mailer constructor
- getSetting() : mixed
- Get a shop setting value
- initialize() : void
- Initialize mailer settings and configurations
- log() : void
- sendAlertEmail() : bool
- Send an alert email
- sendFeedbackEmail() : bool
- Send a feedback email
- sendMail() : bool
- Send an email
- sendOrderEmail() : bool
- Send an order email
- setAlertRecipients() : void
- Set alert recipients
- setDevRecipients() : void
- Set developer recipients
- setDomain() : void
- Set shop domain
- setFeedbackRecipients() : void
- Set feedback recipients
- setMailerMethod() : void
- Set the mailer method and type
- setOrderRecipients() : void
- Set order recipients
- setSetting() : void
- Set a shop setting value
- setShopSettings() : void
- Set shop settings and reinitialize mailer
- setTestRecipients() : void
- Set test recipients
- executeMailSend() : bool
- Execute email sending through configured mailer
- formatContextMessage() : string
- Format message with context data
- handleAttachments() : mixed
- Handle email attachments
- initializeMailer() : void
- Initialize mailer based on current settings
- sendViaMailFunction() : bool
- Send email using PHP's mail() function
- sendViaPhpMailer() : bool
- Send email using PHPMailer
- sendViaSendGrid() : bool
- Send email using SendGrid
- sendViaSymfony() : bool
- Send email using Symfony Mailer
Properties
$alertRecipients
private
array<string|int, mixed>|string
$alertRecipients
= []
Email recipients for alerts
$charset
private
string
$charset
= 'utf-8'
Email character encoding
$devRecipients
private
array<string|int, mixed>|string
$devRecipients
= []
Email recipients for developer notifications
$feedbackRecipients
private
array<string|int, mixed>|string
$feedbackRecipients
= []
Email recipients for feedback
$logger
private
object|null
$logger
= null
$mailerMethod
private
string
$mailerMethod
Mailer method (phpmailer, sendgrid, symfony)
$mailerMethodDefaults
private
array<string|int, mixed>
$mailerMethodDefaults
= []
Default mailer methods for different types
$mailerSettings
private
array<string|int, mixed>
$mailerSettings
Configuration settings for mailer
$mailerType
private
string
$mailerType
Type of mailer (shop, dev)
$orderRecipients
private
array<string|int, mixed>|string
$orderRecipients
= []
Email recipients for order notifications
$sendGrid
private
SendGrid|null
$sendGrid
= null
SendGrid instance
$shopDomain
private
string
$shopDomain
Shop domain name
$shopEnvironment
private
string
$shopEnvironment
Current shop environment (dev, test, staging, live)
$shopSettings
private
array<string|int, mixed>
$shopSettings
Shop configuration settings
$symfony
private
Mailer|null
$symfony
= null
Symfony Mailer instance
$testRecipients
private
array<string|int, mixed>|string
$testRecipients
= []
Email recipients for test emails
$wordWrap
private
int
$wordWrap
= 50
Word wrap length for emails
Methods
__construct()
Mailer constructor
public
__construct([array<string|int, mixed> $shopSettings = [] ][, string $mailerMethod = 'phpmailer' ][, string $mailerType = 'shop' ]) : mixed
Parameters
- $shopSettings : array<string|int, mixed> = []
-
Shop configuration settings
- $mailerMethod : string = 'phpmailer'
-
Mailer method (phpmailer, sendgrid, symfony)
- $mailerType : string = 'shop'
-
Mailer type (shop, dev)
getSetting()
Get a shop setting value
public
getSetting(string $key[, mixed $default = '' ]) : mixed
Parameters
- $key : string
-
Setting key
- $default : mixed = ''
-
Default value if key not found
Return values
mixed —Setting value
initialize()
Initialize mailer settings and configurations
public
initialize() : void
Tags
log()
public
log([mixed $message = '' ][, string $level = 'info' ][, mixed $backtrace = null ][, int $spacing = 0 ]) : void
Parameters
- $message : mixed = ''
- $level : string = 'info'
- $backtrace : mixed = null
- $spacing : int = 0
sendAlertEmail()
Send an alert email
public
sendAlertEmail(string $subject, string $message[, array<string|int, mixed> $context = [] ][, array<string|int, mixed> $attachment = [] ]) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $context : array<string|int, mixed> = []
-
Additional context data
- $attachment : array<string|int, mixed> = []
-
Attachments
Return values
bool —True if email was sent successfully
sendFeedbackEmail()
Send a feedback email
public
sendFeedbackEmail(string $subject, string $message) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
Return values
bool —True if email was sent successfully
sendMail()
Send an email
public
sendMail(string $subject, string $message, string|array<string|int, mixed> $to[, string|array<string|int, mixed> $cc = [] ][, string|array<string|int, mixed> $bcc = [] ][, array<string|int, mixed> $attachment = [] ][, string $mailerType = 'shop' ][, string $mailerMethod = '' ]) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $to : string|array<string|int, mixed>
-
Recipient email address(es)
- $cc : string|array<string|int, mixed> = []
-
CC email address(es)
- $bcc : string|array<string|int, mixed> = []
-
BCC email address(es)
- $attachment : array<string|int, mixed> = []
-
Attachments
- $mailerType : string = 'shop'
-
Mailer type (shop, dev)
- $mailerMethod : string = ''
-
Mailer method (phpmailer, sendgrid, symfony)
Return values
bool —True if email was sent successfully
sendOrderEmail()
Send an order email
public
sendOrderEmail(string $subject, string $customerEmail, string $message[, array<string|int, mixed> $attachment = [] ]) : bool
Parameters
- $subject : string
-
Email subject
- $customerEmail : string
-
Customer email address
- $message : string
-
Email message body
- $attachment : array<string|int, mixed> = []
-
Attachments
Return values
bool —True if email was sent successfully
setAlertRecipients()
Set alert recipients
public
setAlertRecipients(array<string|int, mixed>|string $alertRecipients) : void
Parameters
- $alertRecipients : array<string|int, mixed>|string
-
Email addresses for alerts
setDevRecipients()
Set developer recipients
public
setDevRecipients(array<string|int, mixed>|string $devRecipients) : void
Parameters
- $devRecipients : array<string|int, mixed>|string
-
Email addresses for developer notifications
setDomain()
Set shop domain
public
setDomain(string $domain) : void
Parameters
- $domain : string
-
Shop domain name
setFeedbackRecipients()
Set feedback recipients
public
setFeedbackRecipients(array<string|int, mixed>|string $feedbackRecipients) : void
Parameters
- $feedbackRecipients : array<string|int, mixed>|string
-
Email addresses for feedback
setMailerMethod()
Set the mailer method and type
public
setMailerMethod([string $mailerMethod = 'phpmailer' ][, string $mailerType = 'shop' ]) : void
Parameters
- $mailerMethod : string = 'phpmailer'
-
Mailer method (phpmailer, sendgrid, symfony)
- $mailerType : string = 'shop'
-
Mailer type (shop, dev)
setOrderRecipients()
Set order recipients
public
setOrderRecipients(array<string|int, mixed>|string $orderRecipients) : void
Parameters
- $orderRecipients : array<string|int, mixed>|string
-
Email addresses for order notifications
setSetting()
Set a shop setting value
public
setSetting(string $key, string $value) : void
Parameters
- $key : string
-
Setting key
- $value : string
-
Setting value
setShopSettings()
Set shop settings and reinitialize mailer
public
setShopSettings(array<string|int, mixed> $shopSettings) : void
Parameters
- $shopSettings : array<string|int, mixed>
-
Shop configuration settings
setTestRecipients()
Set test recipients
public
setTestRecipients(array<string|int, mixed>|string $testRecipients) : void
Parameters
- $testRecipients : array<string|int, mixed>|string
-
Email addresses for test emails
executeMailSend()
Execute email sending through configured mailer
private
executeMailSend(string $subject, string $message, array<string|int, mixed> $recipients[, array<string|int, mixed> $cc = [] ][, array<string|int, mixed> $bcc = [] ][, array<string|int, mixed> $attachment = [] ][, string $mailerType = 'shop' ][, string $mailerMethod = '' ]) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $recipients : array<string|int, mixed>
-
Recipient email addresses
- $cc : array<string|int, mixed> = []
-
CC email addresses
- $bcc : array<string|int, mixed> = []
-
BCC email addresses
- $attachment : array<string|int, mixed> = []
-
Attachments
- $mailerType : string = 'shop'
-
Mailer type (shop, dev)
- $mailerMethod : string = ''
-
Mailer method (phpmailer, sendgrid, symfony)
Return values
bool —True if email was sent successfully
formatContextMessage()
Format message with context data
private
formatContextMessage(string $message, array<string|int, mixed> $context) : string
Parameters
- $message : string
-
Main message content
- $context : array<string|int, mixed>
-
Additional context data
Return values
string —Formatted message with context
handleAttachments()
Handle email attachments
private
handleAttachments(mixed $email, array<string|int, mixed> $attachments) : mixed
Parameters
- $email : mixed
-
Email object
- $attachments : array<string|int, mixed>
-
Array of attachments
initializeMailer()
Initialize mailer based on current settings
private
initializeMailer() : void
sendViaMailFunction()
Send email using PHP's mail() function
private
sendViaMailFunction(string $subject, string $message, array<string|int, mixed>|string $to[, array<string|int, mixed> $cc = [] ][, array<string|int, mixed> $bcc = [] ]) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $to : array<string|int, mixed>|string
-
Recipient email address(es)
- $cc : array<string|int, mixed> = []
-
CC email addresses
- $bcc : array<string|int, mixed> = []
-
BCC email addresses
Return values
bool —True if email was sent successfully
sendViaPhpMailer()
Send email using PHPMailer
private
sendViaPhpMailer(string $subject, string $message, array<string|int, mixed> $config, array<string|int, mixed> $recipients[, array<string|int, mixed> $cc = [] ][, array<string|int, mixed> $bcc = [] ][, array<string|int, mixed> $attachment = [] ]) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $config : array<string|int, mixed>
-
Mailer configuration
- $recipients : array<string|int, mixed>
-
Recipient email addresses
- $cc : array<string|int, mixed> = []
-
CC email addresses
- $bcc : array<string|int, mixed> = []
-
BCC email addresses
- $attachment : array<string|int, mixed> = []
-
Attachments
Return values
bool —True if email was sent successfully
sendViaSendGrid()
Send email using SendGrid
private
sendViaSendGrid(string $subject, string $message, array<string|int, mixed> $config, array<string|int, mixed> $recipients, array<string|int, mixed> $bcc, array<string|int, mixed> $cc, array<string|int, mixed> $attachment) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $config : array<string|int, mixed>
-
Mailer configuration
- $recipients : array<string|int, mixed>
-
Recipient email addresses
- $bcc : array<string|int, mixed>
-
BCC email addresses
- $cc : array<string|int, mixed>
-
CC email addresses
- $attachment : array<string|int, mixed>
-
Attachments
Return values
bool —True if email was sent successfully
sendViaSymfony()
Send email using Symfony Mailer
private
sendViaSymfony(string $subject, string $message, array<string|int, mixed> $config, array<string|int, mixed> $recipients, array<string|int, mixed> $cc, array<string|int, mixed> $bcc, array<string|int, mixed> $attachment) : bool
Parameters
- $subject : string
-
Email subject
- $message : string
-
Email message body
- $config : array<string|int, mixed>
-
Mailer configuration
- $recipients : array<string|int, mixed>
-
Recipient email addresses
- $cc : array<string|int, mixed>
-
CC email addresses
- $bcc : array<string|int, mixed>
-
BCC email addresses
- $attachment : array<string|int, mixed>
-
Attachments
Return values
bool —True if email was sent successfully