PHP code example of jeffersongoncalves / filament-mail
1. Go to this page and download the library: Download jeffersongoncalves/filament-mail 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/ */
jeffersongoncalves / filament-mail example snippets
use JeffersonGoncalves\FilamentMail\FilamentMailPlugin;
use LaraZeus\SpatieTranslatable\SpatieTranslatablePlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FilamentMailPlugin::make(),
// Required for multi-locale template editing
SpatieTranslatablePlugin::make()
->defaultLocales(['en', 'pt_BR', 'es']),
]);
}
FilamentMailPlugin::make()
->navigationGroup('Email')
->navigationIcon('heroicon-o-envelope')
->navigationSort(50)
->mailLogResource() // Enable/disable mail log resource
->mailTemplateResource() // Enable/disable template resource
->mailSuppressionResource() // Enable/disable suppression resource
->statsWidgets() // Enable/disable stats widgets
->analyticsWidget() // Enable/disable analytics charts
->dashboard() // Enable/disable dashboard page
->tenantScoping() // Enable/disable tenant scoping
FilamentMailPlugin::make()
->mailSuppressionResource(false) // Disable suppression management
->analyticsWidget(false) // Disable analytics charts
->dashboard(false) // Disable dashboard page
// config/filament-mail.php
return [
'resources' => [
'mail_log' => [
'enabled' => true,
'label' => 'Mail Log',
'plural_label' => 'Mail Logs',
],
'mail_template' => [
'enabled' => true,
'label' => 'Mail Template',
'plural_label' => 'Mail Templates',
],
'mail_suppression' => [
'enabled' => true,
'label' => 'Suppression',
'plural_label' => 'Suppressions',
],
],
'widgets' => [
'stats_overview' => true,
'analytics_chart' => true,
'delivery_rate_chart' => true,
],
'dashboard' => [
'enabled' => true,
],
'navigation' => [
'group' => 'Email',
'icon' => 'heroicon-o-envelope',
'sort' => 50,
],
'template_editor' => [
'driver' => env('FILAMENT_MAIL_EDITOR', 'rich_editor'),
'locales' => ['en'],
'default_locale' => 'en',
'unlayer_project_id' => env('UNLAYER_PROJECT_ID'),
'merge_tags' => [],
],
'preview' => [
'max_width' => '800px',
'sandbox' => true,
],
'tenant_scoping' => false,
];
use JeffersonGoncalves\FilamentMail\Contracts\TemplateEditorContract;
class MyEditorDriver implements TemplateEditorContract
{
public function getFormField(string $fieldName = 'html_body'): Component
{
return MyCustomField::make($fieldName)->columnSpanFull();
}
public function render(string $content, array $variables): string
{
foreach ($variables as $key => $value) {
$content = str_replace(
['{{' . $key . '}}', '{{ ' . $key . ' }}'],
(string) $value,
$content
);
}
return $content;
}
}
// In a service provider:
$this->app->bind(TemplateEditorContract::class, MyEditorDriver::class);
use JeffersonGoncalves\FilamentMail\Notifications\MailNotification;
// Simple notification
$user->notify(new MailNotification(
templateKey: 'auth.welcome',
variables: [
'name' => $user->name,
'login_url' => route('login'),
],
));
// With locale, cc, and attachments
$user->notify(new MailNotification(
templateKey: 'transactional.invoice',
variables: [
'invoice_number' => $invoice->number,
'total' => number_format($invoice->total, 2, ',', '.'),
'due_date' => $invoice->due_date->format('d/m/Y'),
],
metadata: [
'locale' => 'pt_BR',
'cc' => ['[email protected] '],
'attachments' => [storage_path("invoices/{$invoice->number}.pdf")],
],
));
// Without a notifiable (via Notification facade)
use Illuminate\Support\Facades\Notification;
Notification::route('mail', $email)->notify(
new MailNotification('auth.reset-password', ['url' => $resetUrl])
);
use JeffersonGoncalves\FilamentMail\Traits\HasMailTemplate;
use Illuminate\Mail\Mailable;
class WelcomeMail extends Mailable
{
use HasMailTemplate;
public function __construct(User $user)
{
$this->templateKey = 'auth.welcome';
$this->templateVariables = ['name' => $user->name];
}
public function build(): static
{
return $this->buildContent();
}
}
// config/filament-mail.php
'resources' => [
'mail_log' => [
'class' => App\Filament\Resources\CustomMailLogResource::class,
],
],
bash
php artisan vendor:publish --tag="laravel-mail-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="filament-mail-config"
bash
php artisan vendor:publish --tag="filament-mail-migrations"
php artisan migrate