PHP code example of xammie / mailbook

1. Go to this page and download the library: Download xammie/mailbook 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/ */

    

xammie / mailbook example snippets


// This will use dependency injection if your mailable has parameters
Mailbook::add(VerificationMail::class);

// Use a closure to customize the parameters of the mail instance
Mailbook::add(function (): VerificationMail {
    $user = User::factory()->make();

    return new VerificationMail($user, '/example/url')
});

// Mailable
Mailbook::add(VerificationMail::class);

// Notification
Mailbook::add(InvoiceCreatedNotification::class);

// With dependency injection
Mailbook::add(function (VerificationService $verificationService): VerificationMail {
    return new VerificationMail($verificationService, '/example/url');
});

// Without dependency injection
Mailbook::add(function (): VerificationMail {
    $verificationService = app(VerificationService::class);
    
    return new VerificationMail($verificationService, '/example/url');
});

$user = User::factory()->create();

Mailbook::to($user)->add(WelcomeNotification::class);

Mailbook::to('[email protected]')->add(WelcomeNotification::class)

Mailbook::category('Invoices')->group(function () {
    Mailbook::add(InvoiceCreatedNotification::class);
    Mailbook::add(InvoicePaidNotification::class);
});

Mailbook::to('[email protected]')->group(function () {
    Mailbook::add(WelcomeNotification::class);
    Mailbook::add(TrialEndedNotification::class);
});

Mailbook::to('[email protected]')
    ->category('Invoices')
    ->group(function () {
        // ...
    });

// Use a closure to customize the parameters of the mail instance
Mailbook::add(OrderCreatedMail::class)
    ->variant('1 item', fn () => new OrderCreatedMail(Order::factory()->withOneProduct()->create()))
    ->variant('2 items', fn () => new OrderCreatedMail(Order::factory()->withTwoProducts()->create()));

'locales' => [
    'en' => 'English',
    'nl' => 'Dutch',
    'de' => 'German',
    'es' => 'Spanish'
],

'database_rollback' => true,

// All database changes are rolled back after rendering the mail.
Mailbook::add(function (): OrderShippedMail {
    $order = Order::factory()->create();
    $tracker = Tracker::factory()->create();
        
    return new OrderShippedMail($order, $tracker);
});

'send' => true,
'send_to' => '[email protected]',
bash
php artisan mailbook:install
bash
php artisan vendor:publish --tag="mailbook-config"
bash
php artisan vendor:publish --tag="mailbook-views"