Luminova Framework

PHP Luminova: Abstract Base Class for Email Templates

Last updated: 2025-11-26 08:48:46

The Base Mailer class allows you build reusable email templates and send them easily through the Luminova email system. It handles the structure of the message so you only define the contents to send.

The Base Mailer class is the core of Luminova’s email system. It gives you a simple structure for building your own email templates. You define the subject, HTML content, plain-text fallback, and any attachments. Luminova handles the sending; you only focus on what the email should contain.


Examples

Creating Your Own Email Template

A template is just a small class that tells Luminova what the email should look like.You extend Mailer, then return the subject, HTML message, text fallback, and any files you want to attach.

// app/Models/Emails/OrderTemplate.php
namespace App\Models\Emails;

use Luminova\Base\Mailer;

class OrderTemplate extends Mailer
{
    public function getSubject(): ?string
    {
        return 'Order Completed';
    }

    public function getHtml(): ?string
    {
        return '<p>Your order has been completed successfully.</p>';
    }

    public function getText(): ?string
    {
        return 'Your order has been completed successfully.';
    }

    public function getFiles(): ?array
    {
        return null; // Return an array of file paths if you need attachments
    }
}

What’s happening:You tell Luminova what to send. Nothing more. No magic. No hidden steps.


Sending the Email

Now use the template inside your controller.You only need Mailer::to()->send() and your template class.

// app/Controllers/Http/OrderController.php

namespace App\Controllers\Http;

use Luminova\Base\Controller;
use Luminova\Attributes\Route;
use Luminova\Attributes\Prefix;
use Luminova\Utility\Email\Mailer;
use App\Models\Emails\OrderTemplate;
use App\Models\Orders;

#[Prefix('/order/(:base)')]
class OrderController extends Controller
{
    #[Route('/order/complete/(:integer)')]
    public function complete(int $orderNumber): int
    {
        $order = new Orders();

        $isCompleted = $order->update($orderNumber, [
            'status' => 'completed'
        ]);

        if ($isCompleted) {
            Mailer::to('[email protected]')
                ->send(new OrderTemplate());
        }

        return $this->view('order_completed', [
            'orderNumber' => $orderNumber,
            'status' => $isCompleted,
            'message' => $isCompleted
                ? 'Thank you for your order!'
                : 'Order failed!'
        ]);
    }
}

How it works:

  1. Update the order status.
  2. If the update succeeds, send the email.
  3. The OrderTemplate decides what the email looks like.

Class Definition


Methods

getSubject

Get the subject of the email.

public getSubject(): ?string

Return Value:

string|null - The subject of the email.


getHtml

Get the HTML body of the email.

public getHtml(): ?string

Return Value:

string|null - Return email template html body.


getText

Get the TEXT body of the email.

public getText(): ?string

Return Value:

string|null - Return email template alt text body.


getFiles

Get the attachments of the email.

public getFiles(): ?array

Return Value:

array<string,string>|null - Return arrays of attachments or null if not attachment to send.

Array keys

  • path: The file path.
  • name: Optional file name.
  • encoding: File encoding (default: base64).
  • type: Optional file type.
  • disposition: File disposition (default: attachment)