PHP code example of basementdevs / filament-better-mails
1. Go to this page and download the library: Download basementdevs/filament-better-mails 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/ */
basementdevs / filament-better-mails example snippets
use Basement\BetterMails\Filament\FilamentBetterEmailPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(FilamentBetterEmailPlugin::make());
}
return [
'mails' => [
'models' => [
'mail' => \Basement\BetterMails\Core\Models\BetterEmail::class,
'event' => \Basement\BetterMails\Core\Models\BetterEmailEvent::class,
'attachment' => \Basement\BetterMails\Core\Models\BetterEmailAttachment::class,
],
'database' => [
'tables' => [
'mails' => 'mails',
'attachments' => 'mail_attachments',
'events' => 'mail_events',
'polymorph' => 'mailables',
],
'pruning' => [
'enabled' => false,
'after' => 30, // days
],
],
'headers' => [
'key' => 'X-Better-Mails-Event-ID',
],
'logging' => [
'attachments' => [
'enabled' => env('MAILS_LOGGING_ATTACHMENTS_ENABLED', true),
'disk' => env('FILESYSTEM_DISK', 'local'),
'root' => 'mails/attachments',
],
],
],
'webhooks' => [
'provider' => env('MAILS_WEBHOOK_PROVIDER', 'resend'),
'logging' => [
'channel' => env('MAILS_WEBHOOK_LOG_CHANNEL'),
'enabled' => env('MAILS_WEBHOOK_LOGGING_ENABLED', false),
],
'drivers' => [
'resend' => [
'driver' => \Basement\BetterMails\Resend\ResendDriver::class,
'key_secret' => env('RESEND_WEBHOOK_SECRET'),
],
],
],
'resource' => [
'navigation_group' => 'Emails',
'navigation_label' => 'Emails',
'label' => 'Email',
'slug' => 'mails',
'navigation_icon' => 'heroicon-o-envelope', // null to hide icon
],
'view_any' => true,
];
'models' => [
'mail' => \App\Models\Email::class,
'event' => \App\Models\EmailEvent::class,
'attachment' => \App\Models\EmailAttachment::class,
],
'database' => [
'tables' => [
'mails' => 'email_logs',
'attachments' => 'email_attachments',
'events' => 'email_events',
'polymorph' => 'email_mailables',
],
],
'resource' => [
'navigation_group' => 'Communications',
'navigation_label' => 'Email Logs',
'label' => 'Email Log',
'slug' => 'email-logs',
'navigation_icon' => 'heroicon-o-inbox', // set to null to hide icon
],
'pruning' => [
'enabled' => true,
'after' => 60, // days
],
use Illuminate\Support\Facades\Schedule;
Schedule::command('model:prune', [
'--model' => \Basement\BetterMails\Core\Models\BetterEmail::class,
])->daily();
'logging' => [
'attachments' => [
'enabled' => true, // set to false to skip attachment storage
'disk' => 'local', // any filesystem disk
'root' => 'mails/attachments',
],
],
'webhooks' => [
'logging' => [
'enabled' => true,
'channel' => 'webhook', // custom log channel
],
],
use Basement\BetterMails\Core\Models\BetterEmail;
class Email extends BetterEmail
{
// Add custom relationships, scopes, accessors, etc.
}
// config/filament-better-mails.php
'models' => [
'mail' => \App\Models\Email::class,
],
use Basement\BetterMails\Core\AbstractMailDriver;
class PostmarkDriver extends AbstractMailDriver
{
public function handle(array $data): void
{
// Parse webhook payload and dispatch events
}
}
'webhooks' => [
'provider' => 'postmark',
'drivers' => [
'postmark' => [
'driver' => \App\Mail\Drivers\PostmarkDriver::class,
'key_secret' => env('POSTMARK_WEBHOOK_SECRET'),
],
],
],
// The migration creates:
// mailables (configurable) -> id, mail_id (FK), mailable_type, mailable_id
bash
php artisan vendor:publish --tag="filament-better-mails-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-better-mails-config"
bash
php artisan vendor:publish --tag="filament-better-mails-views"