1. Go to this page and download the library: Download mosaiqo/mailer-php 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/ */
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;
// A Mailable through the transport (MAIL_MAILER=mailer)
Mail::to('[email protected]')->send(new WelcomeMail($user));
// A plain message
Mail::raw('Hello world', fn ($m) => $m->to('[email protected]')->subject('Hi'));
$result = $client->notifications()->send([
'to' => '[email protected]',
'title' => 'Your order shipped',
'body' => 'Tracking #1234 is on its way.',
'channels' => ['in_app', 'push'], // optional; defaults to ['in_app']
'action_url' => 'https://app.example.com/orders/1234',
'variables' => ['first_name' => 'Jane'],
]);
if (! $result->anyQueued()) {
// Nothing could be delivered — inspect the per-channel outcomes below.
}
foreach ($result->messages as $channel) {
// $channel->channel, $channel->id, $channel->status, $channel->errorCode
}
$push = $result->channel('push');
if ($push && ! $push->queued()) {
echo $push->errorCode; // e.g. push_provider_not_configured
}
$result = $client->push()->register('[email protected]', 'fcm-device-token', 'android');
echo $result->registered; // true
echo $result->devices; // number of push devices now on the contact
$removed = $client->push()->remove('[email protected]', 'fcm-device-token');
echo $removed->removed; // true, or false if the contact had no such token
use Mailer\Sdk\Exception\ValidationException;
use Mailer\Sdk\Exception\RateLimitException;
use Mailer\Sdk\Exception\MailerException;
try {
$client->send()->email(['to' => '[email protected]', 'template' => 'welcome']);
} catch (ValidationException $e) {
if ($e->getErrorCode() === 'recipient_suppressed') {
// address is on the suppression list — skip it
}
$fieldErrors = $e->errors(); // ['to' => ['The to field is
// 1. Send through the code under test (sandbox token configured).
$client->send()->email(['to' => '[email protected]', 'template' => 'welcome']);
// 2. The sandbox captures every send — read it back like an inbox.
$message = $client->messages()->list(['status' => 'queued'])->data[0];
// 3. Drive the pipeline: simulate provider/engagement events on that message.
$client->sandbox()->simulate($message->uuid, SandboxResource::EVENT_DELIVERED);
$client->sandbox()->simulate($message->uuid, SandboxResource::EVENT_OPEN);
$client->sandbox()->simulate($message->uuid, SandboxResource::EVENT_CLICK, linkIndex: 0);
// 4. Assert on the resulting state.
$refreshed = $client->messages()->get($message->uuid);
// $refreshed->events now contains delivered / opened / clicked
use Mailer\Sdk\Resources\SandboxResource;
// Available events (plain strings work too):
SandboxResource::EVENT_DELIVERED; // 'delivered'
SandboxResource::EVENT_HARD_BOUNCE; // 'hard_bounce'
SandboxResource::EVENT_SOFT_BOUNCE; // 'soft_bounce'
SandboxResource::EVENT_COMPLAINT; // 'complaint'
SandboxResource::EVENT_OPEN; // 'open'
SandboxResource::EVENT_CLICK; // 'click' — pass linkIndex or url
SandboxResource::EVENT_READ; // 'read'
use Mailer\Sdk\MailerClient;
public function __construct(private MailerClient $mailer) {}
// ...
$this->mailer->send()->email([...]);
use Mailer\Sdk\Laravel\Mail\MailerHeaders;
class WelcomeMail extends Mailable
{
public function build()
{
return $this
->subject('Welcome') // ignored when a template header is present
->withSymfonyMessage(function ($message) {
$headers = $message->getHeaders();
$headers->addTextHeader(MailerHeaders::TEMPLATE, 'welcome');
$headers->addTextHeader(
MailerHeaders::VARIABLES,
json_encode(['first_name' => 'Jane']),
);
});
}
}
use Mailer\Sdk\Laravel\Mail\MailerMessage;
public function toMailer($notifiable): MailerMessage
{
return (new MailerMessage)
->subject('Your order shipped')
->html('<p>It is on the way.</p>')
->text('It is on the way.');
}
return (new MailerMessage)
->template('order-shipped')
->variables(['name' => $notifiable->name]);
use Illuminate\Notifications\Notification;
use Mailer\Sdk\Laravel\Mail\MailerMessage;
class OrderShipped extends Notification
{
public function via($notifiable): array
{
return ['mailer'];
}
public function toMailer($notifiable): MailerMessage
{
return (new MailerMessage)
->subject('Your order shipped')
->html('<p>It is on the way.</p>');
// Or a stored template:
// return (new MailerMessage)->template('order-shipped')->variables(['name' => $notifiable->name]);
}
}