PHP code example of camelmailer / camelmailer-laravel

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

    

camelmailer / camelmailer-laravel example snippets


'mailers' => [
    // ...
    'camelmailer' => [
        'transport' => 'camelmailer',
    ],
],

use App\Mail\OrderShipped;
use Illuminate\Support\Facades\Mail;

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

class OrderShipped extends Mailable
{
    public function __construct(public Order $order) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Your order has shipped');
    }

    public function content(): Content
    {
        return new Content(view: 'emails.orders.shipped');
    }
}

$message->getHeaders()->addTextHeader('X-CamelMailer-Tag', 'order-shipped');
$message->getHeaders()->addTextHeader('X-CamelMailer-Stream', 'transactional');

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class InvoicePaid extends Notification
{
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
            ->subject('Invoice paid')
            ->line('Your invoice has been paid. Thank you!');
    }
}

$user->notify(new InvoicePaid);

use CamelMailer\Laravel\Facades\CamelMailer;

CamelMailer::emails()->send([
    'from' => '[email protected]',
    'to' => ['[email protected]'],
    'subject' => 'Your receipt',
    'html_body' => '<p>Thanks!</p>',
]);

CamelMailer::templates()->render('welcome', ['name' => 'Ada']);
CamelMailer::streams()->list();
CamelMailer::stats()->get();
CamelMailer::bounces()->list();
CamelMailer::dmarc()->summary();
CamelMailer::ping();

// A campaign is content plus an audience. The two ways to create one
// behave differently: createDraft() writes it and waits, createAndSend()
// expands it to the stream's subscribers before the call returns.
CamelMailer::campaigns()->createDraft([
    'stream' => 'newsletter',
    'from' => '[email protected]',
    'name' => 'September',
    'subject' => 'What shipped',
    'text_body' => 'Hello.',
]);
CamelMailer::campaigns()->createAndSend('newsletter', [
    'name' => 'Status update',
    'from' => '[email protected]',
    'text_body' => 'All clear.',
]);

// A broadcast send to an address that is not subscribed is refused, so
// this list is the audience.
CamelMailer::subscribers()->add('newsletter', ['address' => '[email protected]']);
CamelMailer::subscribers()->import('newsletter', ['[email protected]', '[email protected]']);

CamelMailer::layouts()->list();
CamelMailer::inbound()->list(['status' => 'held']);
CamelMailer::logs()->tags();

use CamelMailer\Exceptions\ErrorException;

try {
    Mail::to('[email protected]')->send(new OrderShipped($order));
} catch (ErrorException $e) {
    $e->code; // 'ValidationError', 'Unauthorized', 'NotFound', ...
}
bash
php artisan vendor:publish --tag=camelmailer-config