How samcbdev/mailnotifier works
Purpose and Integration
mailnotifier is a Laravel package for storing email templates in the database, substituting {{placeholder}} values, and sending the resulting email. It is consumed by a host Laravel application through Composer and package discovery/service registration.
Primary package entry points:
• src/NotifyMailServiceProvider.php
• src/Notifymail.php
• src/Facades/NotifyMailFacade.php
Package Bootstrapping
NotifyMailServiceProvider is the Laravel integration boundary. It registers package services and exposes publishable configuration and migration assets for the host application. The host publishes these assets, runs its migration process, and supplies mail configuration through Laravel’s normal environment/configuration.
Relevant paths:
• src/NotifyMailServiceProvider.php
• src/config/notifymail.php
• src/database/migrations/create_email_notifications_table.php
Template Persistence
Email notification templates are persisted in a configurable database table created by the package migration. A template is identified by a unique template ID and contains at least subject/content intended for dynamic replacement.
The model is the persistence-facing component; table naming and related defaults are controlled by package configuration.
Relevant paths:
• src/Models/NotifyMail.php
• src/database/migrations/create_email_notifications_table.php
• src/config/notifymail.php
Public Mail Generation API
Notifymail is the main application-facing service API, surfaced through NotifyMailFacade. Callers provide a template identifier plus ordered replacement arrays for template content and subject. The service retrieves the stored template, identifies replacement fields, and generates a mail-details payload.
Key operations described by the package API:
• inspect available dynamic fields;
• generate substituted subject/content records;
• send a generated mail payload.
Relevant paths:
• src/Notifymail.php
• src/Facades/NotifyMailFacade.php
• src/Models/NotifyMail.php
Dynamic Template Processing
Templates use {{key}} markers. The generation layer parses these markers and replaces them using caller-provided values. Replacement arrays are position-sensitive: callers must provide values for every discovered variable and in the same order as the field inspection result.
This is a significant boundary: template structure comes from the database, while replacement values and delivery metadata come from the host application.
Relevant paths:
• src/Notifymail.php
• src/Models/NotifyMail.php
Delivery Pipeline
After generation, the host application enriches the returned details with recipient, sender, optional comma-separated CC/BCC recipients, and optional attachment data. The package dispatches delivery through Laravel’s mail system, represented by a Mailable and potentially an asynchronous job/controller path.
Relevant paths:
• src/Mail/NotifyMail.php
• src/Jobs/NotifyMailJob.php
• src/Http/Controllers/NotifyMailController.php
Rendering, Runtime, and External Boundaries
The package runs inside PHP/Laravel and depends on Laravel’s database, migration, Blade view rendering, mail transport, and optionally queue infrastructure. Email body rendering is handled through a Blade template, while actual SMTP/API delivery is delegated to the host application’s configured Laravel mail driver.
Relevant paths:
• src/resources/views/temp.blade.php
• src/Mail/NotifyMail.php
• src/Jobs/NotifyMailJob.php
Main entry points: Notifymail.php Notifymail · Mail/NotifyMail.php NotifyMail mailable · NotifyMailJob.php NotifyMailJob · Models/NotifyMail.php NotifyMail model
Components 16
Host Laravel App
Consumes the package and supplies delivery data.
- Application callers · Provide template IDs, replacements, and delivery metadata.
- Published assets · Configuration and migration are published into the host application.
mailnotifier Package
- NotifyMailServiceProvider · Registers package services and publishable assets.
src/NotifyMailServiceProvider.php - NotifyMailFacade · Public static-style API surface.
src/Facades/NotifyMailFacade.php - Notifymail · Inspects fields, generates payloads, and initiates sending.
src/Notifymail.php - NotifyMail model · Reads stored notification templates.
src/Models/NotifyMail.php - notifymail config · Controls table naming and defaults.
src/config/notifymail.php - Template table migration · Creates persistent email notification templates.
src/database/migrations/create_email_notifications_table.php - NotifyMailController · Optional HTTP-oriented delivery path.
src/Http/Controllers/NotifyMailController.php - NotifyMailJob · Optional asynchronous delivery path.
src/Jobs/NotifyMailJob.php - NotifyMail mailable · Builds the outgoing message from generated details.
src/Mail/NotifyMail.php - Email body view · Renders the generated email body.
src/resources/views/temp.blade.php
Laravel Runtime
Host-configured framework services and infrastructure.
- Email templates · Stores template IDs, subjects, and bodies containing markers.
- Laravel container
- Queue infrastructure · Runs queued mail jobs when enabled.
- Mail driver / SMTP API · Configured by the host Laravel application.
Connections 17
- Application callers → NotifyMailFacade: uses API
- NotifyMailFacade → Notifymail: resolves
- NotifyMailServiceProvider → Laravel container: registers services
- NotifyMailServiceProvider → Published assets: publishes
- Published assets → Template table migration: runs copy of
- Template table migration → Email templates: creates
- notifymail config → NotifyMail model: configures table
- Notifymail → NotifyMail model: loads template by ID
- NotifyMail model → Email templates: queries
- Application callers → Notifymail: replacement values and metadata
- Notifymail → NotifyMail mailable: generated mail details
- NotifyMailController → Notifymail: optional send path
- NotifyMailController → NotifyMailJob: may dispatch
- NotifyMailJob → Queue infrastructure: executes on
- NotifyMailJob → NotifyMail mailable: creates
- NotifyMail mailable → Email body view: renders body
- NotifyMail mailable → Mail driver / SMTP API: sends through