Skip to content

Mail Channel ​

The mail channel delivers beautifully formatted transactional HTML and plain-text emails.


The MailMessage Builder ​

To send an email, define a toMail() method in your notification class returning a Jengo\Notifications\Messages\MailMessage instance:

php
namespace App\Notifications;

use Jengo\Notifications\Messages\MailMessage;
use Jengo\Notifications\Notification;

class InvoiceGenerated extends Notification
{
    public function __construct(public array $invoice)
    {
        parent::__construct();
    }

    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage())
            ->subject("Invoice #{$this->invoice['number']} Generated")
            ->greeting("Hello {$notifiable->name},")
            ->line('Your monthly invoice is now ready for review.')
            ->panel('Payment is due within 14 calendar days to avoid interruption of service.')
            ->table(
                headers: ['Item', 'Qty', 'Amount'],
                rows: [
                    ['Cloud Hosting (Pro)', '1', '$99.00'],
                    ['Dedicated IP', '2', '$20.00'],
                ]
            )
            ->action('Download Invoice PDF', site_url("invoices/{$this->invoice['id']}/pdf"), 'primary')
            ->line('If you have already paid this invoice, please disregard this notice.')
            ->salutation('Best regards, Jengo Billing Team');
    }
}

Formatting Capabilities ​

Text Lines (line) ​

Lines added before ->action() become intro lines. Lines added after ->action() become outro lines:

php
$mail->line('This appears above the action button.')
     ->action('Confirm Email', $url)
     ->line('This appears below the action button.');

Call-to-Action Buttons (action) ​

Action buttons are rendered using bulletproof Outlook VML markup to ensure consistent rendering across desktop and mobile email clients:

php
$mail->action('Approve Expense', $url, 'primary'); // 'primary', 'success', 'danger'

Notice Panels (panel) ​

Highlights important notices or disclaimers in a shaded callout box:

php
$mail->panel('Security Note: Never share this verification link with anyone.');

Data Tables (table) ​

Renders a responsive HTML data table:

php
$mail->table(
    headers: ['Description', 'Price'],
    rows: [
        ['Item 1', '$25.00'],
        ['Item 2', '$45.00'],
    ]
);

Attachments ​

Local Files ​

Attach files directly from disk:

php
$mail->attach(WRITEPATH . "invoices/{$invoiceId}.pdf", [
    'as'   => 'Invoice.pdf',
    'mime' => 'application/pdf',
]);

Raw In-Memory Binary Data ​

Attach generated reports (e.g. from jengo/pdf):

php
$pdfData = pdf()->loadView('receipt', ['invoice' => $invoice])->output();

$mail->attachData($pdfData, 'Receipt.pdf', [
    'mime' => 'application/pdf',
]);

Sender & Recipients ​

Override the default sender or add carbon copy recipients:

php
$mail->from('billing@acme.corp', 'Acme Corp Billing')
     ->replyTo('support@acme.corp')
     ->cc(['finance@acme.corp'])
     ->bcc(['audit@acme.corp']);

Themes & Custom Views ​

Built-In Themes ​

Choose between built-in responsive themes configured in app/Config/Notifications.php or set per notification:

php
$mail->theme('dark'); // 'default', 'minimal', 'dark'

Custom View Override ​

To render a custom Blade-like or standard CodeIgniter 4 view instead of the pre-built layout:

php
$mail->view('emails/custom_receipt', [
    'invoice' => $this->invoice,
]);

Released under the MIT License.