PHP code example of bjthecod3r / laravel-zeptomail

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

    

bjthecod3r / laravel-zeptomail example snippets


Mail::to($user)->send(new OrderShipped($order));

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

return [
    'token' => env('ZEPTOMAIL_TOKEN'),
    'region' => env('ZEPTOMAIL_REGION', 'com'),
    'bounce_address' => env('ZEPTOMAIL_BOUNCE_ADDRESS'),
    'track_opens' => env('ZEPTOMAIL_TRACK_OPENS'),
    'track_clicks' => env('ZEPTOMAIL_TRACK_CLICKS'),
    'http' => [
        'timeout' => (float) env('ZEPTOMAIL_TIMEOUT', 30),
        'connect_timeout' => (float) env('ZEPTOMAIL_CONNECT_TIMEOUT', 10),
        'retry_times' => (int) env('ZEPTOMAIL_RETRY_TIMES', 1),
        'retry_sleep' => (int) env('ZEPTOMAIL_RETRY_SLEEP', 200),
    ],
];

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

Mail::raw('Hello there', fn ($message) => $message->to('[email protected]')->subject('Hi'));

$user->notify(new InvoicePaid($invoice));

use BjTheCod3r\ZeptoMail\ZeptoMail;
use Illuminate\Mail\Mailables\Envelope;
use Symfony\Component\Mime\Email;

public function envelope(): Envelope
{
    return new Envelope(
        subject: 'Your order has shipped',
        using: [
            fn (Email $message) => ZeptoMail::message($message)
                ->clientReference("order-{$this->order->id}")
                ->trackOpens()
                ->trackClicks(false),
        ],
    );
}

public function envelope(): Envelope
{
    return new Envelope(
        using: [
            fn (Email $message) => ZeptoMail::message($message)
                ->template('2d6f.34a5b1c7d8e9f0a1.k1.abc...')
                ->mergeInfo([
                    'name' => $this->user->name,
                    'order_id' => $this->order->id,
                ]),
        ],
    );
}

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

    'zeptomail-eu' => [
        'transport' => 'zeptomail',
        'region' => 'eu',
        'token' => env('ZEPTOMAIL_EU_TOKEN'),
    ],
],

Mail::mailer('zeptomail-eu')->to($user)->send(new OrderShipped($order));

use BjTheCod3r\ZeptoMail\Exceptions\ZeptoMailTransportException;

try {
    Mail::to($user)->send(new OrderShipped($order));
} catch (ZeptoMailTransportException $e) {
    report($e);

    $e->statusCode; // 400
    $e->errorCode;  // 'TM_3201'
    $e->requestId;  // 'ac41f2b0-...' — quote this to Zoho support
    $e->details;    // the decoded error body, including per-field errors
}

$sent = Mail::to($user)->send(new OrderShipped($order));

$sent->getMessageId(); // 'ac41f2b0-8f3e-11f0-...'

Mail::fake();

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

Mail::assertSent(OrderShipped::class);

use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;

Http::fake([
    'api.zeptomail.*' => Http::response(['request_id' => 'req-1'], 201),
]);

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

Http::assertSent(function (Request $request): bool {
    return $request->url() === 'https://api.zeptomail.com/v1.1/email'
        && $request['subject'] === 'Your order has shipped'
        && $request['to'][0]['email_address']['address'] === '[email protected]';
});
bash
php artisan vendor:publish --tag=zeptomail-config