1. Overview

WHMS uses a template-based email system. Email templates are stored in the database and can be managed from the admin panel (Settings > Email Templates). Templates support dynamic variable replacement using @{{variable_name}} syntax. Emails are sent via Laravel's Mail system using the configured mail driver (SMTP, Mailgun, etc.).

2. Architecture

ComponentLocationPurpose
EmailTemplate Modelapp/Models/EmailTemplate.phpStores templates with slug, subject, HTML/text body, and variables list
TemplateMail Mailableapp/Mail/TemplateMail.phpRenders and sends emails using a template + variables
NotificationServiceapp/Services/NotificationService.phpCentral service that orchestrates email + database notification + SMS delivery
EmailTemplateControllerapp/Http/Controllers/Admin/EmailTemplateController.phpAdmin CRUD for managing email templates
LogSentEmail Listenerapp/Listeners/LogSentEmail.phpLogs all sent emails to ActivityLog

3. Pre-configured Email Templates

Template SlugTriggerDescription
invoice-createdNew invoice generatedNotifies client of a new invoice with amount, due date, and payment link
invoice-paidInvoice payment receivedConfirms payment received with amount and payment date
invoice-overdueInvoice becomes overdueAlerts client that invoice is past due with balance and days overdue
invoice-reminderUpcoming payment dueReminds client of upcoming payment (sent at configured intervals before due date)
invoice-overdue-reminderOverdue follow-upUrgent reminder for overdue invoices (sent at configured intervals after due date)

4. Available Template Variables

VariableDescriptionAvailable In
@{{client_name}}Full name of the clientAll templates
@{{client_first_name}}First name of the clientAll templates
@{{invoice_number}}Invoice number (e.g. INV-20260414-A1B2C)All templates
@{{invoice_total}}Total invoice amountinvoice-created, invoice-paid
@{{invoice_balance}}Remaining balance dueinvoice-overdue, reminders
@{{invoice_due_date}}Due date formattedAll templates
@{{invoice_url}}Link to view invoice in client portalAll templates
@{{currency}}Currency code (e.g. BDT)All templates
@{{company_name}}Company name from settingsAll templates
@{{paid_at}}Payment date/timeinvoice-paid
@{{days_overdue}}Number of days past dueinvoice-overdue, overdue-reminder
@{{days_until_due}}Days until due dateinvoice-reminder
@{{due_label}}Human-readable due statusReminders (e.g. "due in 3 days")

5. Event-Driven Email Flow

EventListenerEmail Template
InvoiceCreatedNotifyInvoiceCreatedinvoice-created
InvoicePaidNotifyInvoicePaidinvoice-paid
InvoiceOverdueNotifyInvoiceOverdueinvoice-overdue
Scheduled ReminderSendInvoiceReminderinvoice-reminder / invoice-overdue-reminder
All emails are also logged in the Activity Log. Check Admin > Logs > Activity Log and filter by "email_sent" action.

6. Email Configuration

Mail driver settings are configured in the .env file: