1. Go to this page and download the library: Download nvl/mail-notifications 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/ */
nvl / mail-notifications example snippets
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailable;
use Nvl\MailNotifications\Contracts\TrackableMessage;
use Nvl\MailNotifications\Laravel\Concerns\TracksMailDelivery;
use Nvl\MailNotifications\ValueObjects\TrackingContext;
final class ReceiptMail extends Mailable implements TrackableMessage
{
use TracksMailDelivery;
public function trackingContext(): TrackingContext
{
return TrackingContext::forCategory('receipt');
}
public function envelope(): Envelope
{
return new Envelope(subject: 'Receipt');
}
public function content(): Content
{
return new Content(markdown: 'mail.receipt');
}
}
Mail::to($recipient)->send(
(new ReceiptMail)->withoutMailTracking(),
);
use DomainException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Nvl\MailNotifications\Exceptions\UnmatchedDeliveryEventException;
use Nvl\MailNotifications\Services\WebhookProcessor;
use Nvl\MailNotifications\ValueObjects\WebhookRequest;
use Throwable;
public function __invoke(
Request $request,
WebhookProcessor $webhooks,
): Response {
try {
$webhooks->process(
provider: 'mailersend',
request: WebhookRequest::fromLaravelRequest(
provider: 'mailersend',
request: $request,
),
);
} catch (UnmatchedDeliveryEventException) {
return response()->noContent(503);
} catch (DomainException) {
return response()->noContent(400);
} catch (Throwable $exception) {
report($exception);
return response()->noContent(503);
}
return response()->noContent();
}
use Throwable;
public function failed(?Throwable $exception): void
{
$this->recordMailTrackingFailure($exception);
// Host-owned alerting or cleanup...
}
use Nvl\MailNotifications\Models\MailNotification;
use Nvl\MailNotifications\Models\MailNotificationEvent;
use Nvl\MailNotifications\Models\ScheduledMailMessage;
$notification = MailNotification::factory()->delivered()->create();
$event = MailNotificationEvent::factory()
->for($notification)
->bounced()
->create();
$scheduledMessage = ScheduledMailMessage::factory()->processing()->create();