EmailService
in package
Email notification service using PHPMailer.
Sends transactional emails (order confirmations, reservation confirmations) via SMTP. Failures are logged but never block business operations.
Tags
Table of Contents
Properties
- $driver : string
- $fromAddress : string
- $fromName : string
- $host : string
- $logBusinessId : int|null
- $logDir : string
- $logEmailType : string
- $password : string
- $port : int
- $username : string
Methods
- __construct() : mixed
- Initialize the email service with SMTP configuration from environment.
- getLogDir() : string
- Get the path to the email log directory.
- sendContactForm() : bool
- Send a contact form submission to the platform admin.
- sendEmailChangePending() : bool
- Send email change pending notification.
- sendInvoice() : bool
- Send an invoice email to the business owner.
- sendMailingListConfirmation() : bool
- Send mailing list confirmation email.
- sendOrderConfirmation() : bool
- Send an order confirmation email to the customer.
- sendPasswordReset() : bool
- Send a password reset email to a customer.
- sendProfileChangeConfirmation() : bool
- Send profile change confirmation email.
- sendRaw() : bool
- Send a raw HTML email to a specified recipient.
- sendReservationConfirmation() : bool
- Send a reservation confirmation email to the guest.
- sendUnsubscribeConfirmation() : bool
- Send unsubscribe confirmation email.
- sendVerificationCode() : bool
- Send a verification code email for business registration.
- logToDatabase() : void
- Log an email record to the database.
- logToFile() : bool
- Log an email to a file instead of sending via SMTP.
- renderTemplate() : string
- Render a PHP email template to an HTML string.
- send() : bool
Properties
$driver
private
string
$driver
Mail driver: 'smtp' (default) or 'log' (saves to file)
$fromAddress
private
string
$fromAddress
From email address
$fromName
private
string
$fromName
From name
$host
private
string
$host
SMTP host
$logBusinessId
private
int|null
$logBusinessId
= \null
Business ID context for mail logging
$logDir
private
string
$logDir
Directory for logged emails when driver is 'log'
$logEmailType
private
string
$logEmailType
= 'other'
Email type context for mail logging
$password
private
string
$password
SMTP password
$port
private
int
$port
SMTP port
$username
private
string
$username
SMTP username
Methods
__construct()
Initialize the email service with SMTP configuration from environment.
public
__construct() : mixed
getLogDir()
Get the path to the email log directory.
public
getLogDir() : string
Return values
stringsendContactForm()
Send a contact form submission to the platform admin.
public
sendContactForm(string $name, string $email, string $subject, string $message) : bool
Parameters
- $name : string
-
Sender name
- $email : string
-
Sender email address
- $subject : string
-
Message subject
- $message : string
-
Message body
Return values
bool —True if sent successfully, false otherwise
sendEmailChangePending()
Send email change pending notification.
public
sendEmailChangePending(string $email, string $name, string $newEmail[, int|null $businessId = null ]) : bool
Parameters
- $email : string
-
Current email
- $name : string
-
Customer name
- $newEmail : string
-
Requested new email
- $businessId : int|null = null
-
Business ID for logging
Return values
boolsendInvoice()
Send an invoice email to the business owner.
public
sendInvoice(array<string|int, mixed> $invoice, array<string|int, mixed> $business) : bool
Parameters
- $invoice : array<string|int, mixed>
-
Invoice record
- $business : array<string|int, mixed>
-
Business record
Return values
bool —True if sent successfully
sendMailingListConfirmation()
Send mailing list confirmation email.
public
sendMailingListConfirmation(string $email, string $name, string $businessName, string $confirmUrl[, int|null $businessId = null ]) : bool
Parameters
- $email : string
-
Recipient email
- $name : string
-
Customer name
- $businessName : string
-
Business name
- $confirmUrl : string
-
Confirmation URL
- $businessId : int|null = null
-
Business ID for logging
Return values
boolsendOrderConfirmation()
Send an order confirmation email to the customer.
public
sendOrderConfirmation(array<string|int, mixed> $order, array<string|int, mixed> $items, array<string|int, mixed> $business) : bool
Parameters
- $order : array<string|int, mixed>
-
Order record (from orders table)
- $items : array<string|int, mixed>
-
Order items (from order_items table)
- $business : array<string|int, mixed>
-
Business record
Return values
bool —True if sent successfully, false otherwise
sendPasswordReset()
Send a password reset email to a customer.
public
sendPasswordReset(string $email, string $name, string $resetUrl) : bool
Parameters
- $email : string
-
Recipient email
- $name : string
-
Customer name
- $resetUrl : string
-
Password reset URL
Return values
boolsendProfileChangeConfirmation()
Send profile change confirmation email.
public
sendProfileChangeConfirmation(string $email, string $name, string $businessName, array<string|int, mixed> $changes[, int|null $businessId = null ]) : bool
Parameters
- $email : string
-
Recipient email
- $name : string
-
Customer name
- $businessName : string
-
Business name
- $changes : array<string|int, mixed>
-
List of change descriptions
- $businessId : int|null = null
-
Business ID for logging
Return values
boolsendRaw()
Send a raw HTML email to a specified recipient.
public
sendRaw(string $to, string $subject, string $html) : bool
Parameters
- $to : string
-
Recipient email address
- $subject : string
-
Email subject line
- $html : string
-
HTML body content
Return values
boolsendReservationConfirmation()
Send a reservation confirmation email to the guest.
public
sendReservationConfirmation(array<string|int, mixed> $reservation, array<string|int, mixed> $business) : bool
Parameters
- $reservation : array<string|int, mixed>
-
Reservation record
- $business : array<string|int, mixed>
-
Business record
Return values
bool —True if sent successfully, false otherwise
sendUnsubscribeConfirmation()
Send unsubscribe confirmation email.
public
sendUnsubscribeConfirmation(string $email, string $name, string $businessName[, int|null $businessId = null ]) : bool
Parameters
- $email : string
-
Recipient email
- $name : string
-
Customer name
- $businessName : string
-
Business name
- $businessId : int|null = null
-
Business ID for logging
Return values
boolsendVerificationCode()
Send a verification code email for business registration.
public
sendVerificationCode(string $email, string $code, string $name) : bool
Parameters
- $email : string
-
Recipient email address
- $code : string
-
6-digit verification code
- $name : string
-
Business owner name
Return values
bool —True if sent successfully, false otherwise
logToDatabase()
Log an email record to the database.
private
logToDatabase(string $to, string $subject, string $html, string $status, string|null $errorMessage) : void
Parameters
- $to : string
-
Recipient email
- $subject : string
-
Email subject
- $html : string
-
HTML body
- $status : string
-
'sent' or 'failed'
- $errorMessage : string|null
-
Error message if failed
logToFile()
Log an email to a file instead of sending via SMTP.
private
logToFile(string $to, string $subject, string $html) : bool
Saves the email as an HTML file in the log directory with metadata headers so it can be inspected during testing/development.
Parameters
- $to : string
-
Recipient email address
- $subject : string
-
Email subject line
- $html : string
-
HTML body content
Return values
bool —True if logged successfully
renderTemplate()
Render a PHP email template to an HTML string.
private
renderTemplate(string $template, array<string|int, mixed> $data) : string
Parameters
- $template : string
-
Template filename (without .php extension)
- $data : array<string|int, mixed>
-
Variables to extract into template scope
Return values
string —Rendered HTML
send()
private
send(string $to, string $subject, string $html) : bool
Parameters
- $to : string
- $subject : string
- $html : string