PHP code example of mailkube / mailkube-laravel

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

    

mailkube / mailkube-laravel example snippets


'mailers' => [
    'mailkube' => [
        'transport' => 'mailkube',
    ],
],

use Illuminate\Support\Facades\Mail;

Mail::to('[email protected]')->send(new OrderShipped($order));

app(\Mailkube\Client::class)->emails->send(
    from: 'Acme <[email protected]>',
    to: '[email protected]',
    subject: 'Hello world',
    html: '<p>It works!</p>',
    tags: [new \Mailkube\Model\Tag('campaign', 'spring')],
);

'mailers' => [
    'mailkube' => ['transport' => 'mailkube'],
    'marketing' => [
        'transport' => 'mailkube',
        'api_key' => env('MARKETING_API_KEY'),
    ],
],

Mail::mailer('marketing')->to($user)->send(new Newsletter());

use Symfony\Component\Mailer\Exception\TransportException;

try {
    Mail::to($user)->send(new OrderShipped($order));
} catch (TransportException $e) {
    report($e->getPrevious());   // the SDK exception, with the API's error name and request id
}

use Mailkube\Laravel\Events\WebhookReceived;
use Mailkube\Event\EmailBouncedEvent;
use Mailkube\Event\EmailDeliveredEvent;

class HandleMailkubeWebhook
{
    public function handle(WebhookReceived $received): void
    {
        $event = $received->event;

        if ($event instanceof EmailDeliveredEvent) {
            Log::info('delivered', ['id' => $event->data->emailId]);
        } elseif ($event instanceof EmailBouncedEvent) {
            Suppression::add($event->data->bounce->recipient);
        }
    }
}

Route::post('/hooks/mail', \Mailkube\Laravel\Http\WebhookController::class)
    ->middleware('api');
dotenv
MAILKUBE_LOG_CHANNEL=stack
bash
php artisan vendor:publish --tag=mailkube-config