PHP code example of cboxdk / laravel-postal

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

    

cboxdk / laravel-postal example snippets


// config/mail.php
'mailers' => [
    'postal' => ['transport' => 'postal'], // optional: 'server' => 'cbox-billing'
],

use Cbox\LaravelPostal\Dto\SendMessage;
use Cbox\LaravelPostal\Facades\Postal;

$result = Postal::send(
    SendMessage::create()
        ->to('[email protected]')
        ->from('Cbox <[email protected]>')
        ->subject('Welcome')
        ->tag('onboarding')
        ->html('<p>Hello!</p>'),
);

$result->messageId;                          // RFC message id Postal assigned
$result->recipient('[email protected]')->id; // Postal's per-recipient id

use Cbox\LaravelPostal\Events\PostalMessageBounced;

Event::listen(function (PostalMessageBounced $event) {
    $event->server();                        // 'cbox-billing'
    $event->payload->originalMessage->to;    // who bounced
});

use Cbox\LaravelPostal\Events\PostalInboundMessage;

Event::listen(function (PostalInboundMessage $event) {
    $event->payload->subject;
    $event->payload->plainBody;
    $event->payload->attachments; // decoded content 

// Database-backed: bind your own registry…
$this->app->singleton(ServerRegistry::class, DatabaseServerRegistry::class);

// …or connect ad hoc without any registration:
Postal::connect(new ServerConfig(name: 'tenant-42', url: $url, key: $key))->send($message);

use Cbox\LaravelPostal\Facades\Postal;

$fake = Postal::fake();

// ... code that sends ...

$fake->assertSent(fn ($message, $server) => $server === 'cbox-billing');
bash
composer postal:install
php artisan migrate
bash
php artisan postal:doctor
bash
php artisan postal:webhook-key
# → POSTAL_WEBHOOK_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n..."
bash
php artisan postal:tail