1. Go to this page and download the library: Download finity-labs/fin-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/ */
finity-labs / fin-mail example snippets
use FinityLabs\FinMail\FinMailPlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
FinMailPlugin::make(),
]);
}
FinMailPlugin::make()
->enableSentEmails() // Show the Sent Emails resource (default: true)
->enableThemes() // Show the Themes resource (default: true)
->deleteActionOnEditPage() // Show delete button on edit pages (default: false)
->policyNamespace('App\\Policies') // Where model policies live (default: App\Policies)
use FinityLabs\FinMail\Resources\EmailTemplateResource\EmailTemplateResource;
class MyEmailTemplateResource extends EmailTemplateResource
{
// override what you need
}
FinMailPlugin::make()
->emailTemplateResource(MyEmailTemplateResource::class)
->emailThemeResource(...) // same pattern
->sentEmailResource(...) // same pattern
FinMailPlugin::make()
// Set a shared navigation group for all resources and settings
->navigationGroup('Communications')
// Or configure each resource independently
->emailTemplateNavigationGroup('Email')
->emailThemeNavigationGroup('Email')
->sentEmailNavigationGroup('Logs')
->settingsNavigationGroup('Administration')
// Set sort order for all resources at once (auto-increments: base, +1, +2, +3)
->navigationSort(10)
// Or configure each resource independently
->emailTemplateNavigationSort(10)
->emailThemeNavigationSort(20)
->sentEmailNavigationSort(30)
->settingsNavigationSort(40)
use FinityLabs\FinMail\Mail\TemplateMail;
// Simple
Mail::to($user->email)->send(
TemplateMail::make('welcome-email')
->models(['user' => $user])
);
// With locale, attachments, and overrides
Mail::to($customer->email)->send(
TemplateMail::make('invoice-sent', locale: 'hu')
->models(['customer' => $customer, 'invoice' => $invoice])
->attachFile($invoice->getPdfPath(), "Invoice-{$invoice->number}.pdf")
);
// Logged automatically when logging is enabled in the settings
Mail::to($user->email)->send(
TemplateMail::make('welcome-email')->models(['user' => $user])
);
// Opt out for a single email
TemplateMail::make('internal-report')->withoutLogging();
// Force a log entry even when logging is disabled in the settings
TemplateMail::make('invoice-sent')->withLogging();
// Log the email but keep the rendered body out of the database —
// the built-in password reset and verification emails do this by
// default, since their bodies contain signed URLs
TemplateMail::make('user-password-reset')->withoutStoringRenderedBody();
TemplateMail::make('order-confirmation')
->models(['user' => $user])
->with('trackingUrl', $tracking->url)
// or pass an array:
->extraData([
'orderItems' => $order->items,
'currency' => 'EUR',
]);
// No logo on this one
TemplateMail::make('internal-report')
->withoutLogo();
// Different logo and color for a partner mailing
TemplateMail::make('partner-newsletter')
->overrideBranding([
'logo' => 'https://example.com/partner-logo.png',
'primary_color' => '#0EA5E9',
]);
use FinityLabs\FinMail\Actions\SendEmailAction;
// In your table actions, header actions, or anywhere Filament actions are used
SendEmailAction::make()
->template('invoice-sent')
->recipient(fn (Invoice $record) => $record->customer->email)
->models(fn (Invoice $record) => [
'invoice' => $record,
'customer' => $record->customer,
])
->attachments(fn (Invoice $record) => [
['path' => $record->getPdfPath(), 'name' => "Invoice-{$record->number}.pdf"],
])
->onSent(fn (Invoice $record) => $record->update(['emailed_at' => now()]))
use FinityLabs\FinMail\Traits\HasEmailTemplates;
class Invoice extends Model
{
use HasEmailTemplates;
}
use FinityLabs\FinMail\Resources\RelationManagers\SentEmailsRelationManager;
public static function getRelations(): array
{
return [
SentEmailsRelationManager::class,
];
}
$invoice->sentEmails; // All sent emails
$invoice->latestSentEmail(); // Most recent
$invoice->hasBeenEmailed('invoice-sent'); // Check if a specific template was sent
$invoice->sentEmailsCount(); // Count
use FinityLabs\FinMail\Events\EmailSent;
use FinityLabs\FinMail\Events\EmailFailed;
// In a service provider or listener
Event::listen(EmailSent::class, function (EmailSent $event) {
// $event->sentEmail — the SentEmail model
// $event->template — the EmailTemplate used (nullable)
logger()->info("Email sent to {$event->sentEmail->recipients_display}");
});
Event::listen(EmailFailed::class, function (EmailFailed $event) {
// $event->error — the error message
logger()->error("Email failed: {$event->error}");
});
// A single format for all locales
'date_format' => 'd/m/Y',
'datetime_format' => 'd/m/Y H:i',
// Or an array keyed by locale
'date_format' => [
'en' => 'M d, Y',
'de' => 'd.m.Y',
'hu' => 'Y. m. d.',
],
'datetime_format' => [
'en' => 'M d, Y H:i',
'de' => 'd.m.Y H:i',
'hu' => 'Y. m. d. H:i',
],
use FinityLabs\FinMail\Facades\FinMail;
FinMail::dateFormat(); // string|null for current locale
FinMail::dateTimeFormat(); // string|null for current locale
Schema::table('email_template_versions', function (Blueprint $table) {
$table->dropConstrainedForeignId('created_by');
$table->foreignIdFor(User::class, 'created_by')->nullable()->constrained()->nullOnDelete();
});
Schema::table('sent_emails', function (Blueprint $table) {
$table->dropConstrainedForeignId('sent_by');
$table->foreignIdFor(User::class, 'sent_by')->nullable()->constrained()->nullOnDelete();
});