PHP code example of webteractive / mailulator

1. Go to this page and download the library: Download webteractive/mailulator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

webteractive / mailulator example snippets


// routes/web.php
use Webteractive\Mailulator\Mailulator;

// pick ONE of the following — calling route() more than once registers the group more than once:
Mailulator::route('/');                                        // at root
Mailulator::route('/mail');                                    // custom path
Mailulator::route('/mail', ['middleware' => ['web', 'auth']]); // add your app's auth

protected function gate(): void
{
    Gate::define('viewMailulator', fn ($user) =>
        in_array(optional($user)->email, [
            '[email protected]',
        ])
    );
}

public function boot(): void
{
    parent::boot();

    Mailulator::canViewInbox(fn ($user, $inboxId) =>
        $user->inboxes()->where('inboxes.id', $inboxId)->exists()
    );

    Mailulator::manage(fn ($user) => $user->is_admin ?? false);
}

use Webteractive\Mailulator\Facades\Mailulator;

// Manage inboxes
$billing = Mailulator::createInbox('Billing', ['retention_days' => 7, 'color' => '#0f172a']);
$token   = $billing->token();               // one-time plaintext key
Mailulator::inbox('Billing')->rename('Invoices')->settings(['color' => '#111827']);
Mailulator::inbox('Invoices')->regenerateToken();
Mailulator::inbox('Marketing')->delete();   // throws on the Default or last inbox

// Query emails
Mailulator::inbox('Invoices')->emails();                 // Collection
Mailulator::latest();                                    // newest anywhere
Mailulator::inbox('Invoices')->to('[email protected]')->subject('Welcome')->get();
Mailulator::inbox('Invoices')->unread()->count();

// Test assertions (PHPUnit context)
Mailulator::inbox('Invoices')
    ->assertReceivedFrom('[email protected]')
    ->assertSubject('Welcome');
Mailulator::assertNothingReceived();
Mailulator::flush();                                     // reset between tests

// Seed without sending
Mailulator::inbox('Invoices')->receive([
    'from' => '[email protected]',
    'to' => ['[email protected]'],
    'subject' => 'Seeded',
    'text_body' => 'Hi',
]);
bash
php artisan vendor:publish --tag=mailulator-assets
bash
composer update webteractive/mailulator
php artisan vendor:publish --tag=mailulator-assets --force
php artisan migrate --database=mailulator