This commit is contained in:
Bozhidar 2024-09-19 12:40:11 +03:00
parent 285adb3674
commit 242649aa9e
3 changed files with 96 additions and 1 deletions

View file

@ -0,0 +1,73 @@
<?php
namespace Modules\Email\App\Filament\Pages;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\Page;
class SendEmail extends Page
{
protected static ?string $navigationIcon = 'heroicon-o-paper-airplane';
protected static string $view = 'email::filament.pages.send-email';
protected static ?string $navigationGroup = 'Email';
protected static ?string $navigationLabel = 'Send Email';
protected static ?int $navigationSort = 2;
public $from = '';
public $to = '';
public $body = 'Hi,
Welcome to your new account.
';
public $subject = 'Welcome';
public function form(Form $form): Form
{
$this->from = 'admin@';
return $form
->schema([
TextInput::make('from')
->disabled()
->columnSpanFull(),
TextInput::make('to')
->label('To')
->required()
->columnSpanFull(),
TextInput::make('subject')
->label('Subject')
->required()
->columnSpanFull(),
Textarea::make('body')
->rows(10)
->label('Body')
->required()
->columnSpanFull(),
]);
}
public function send()
{
if (mail($this->to, $this->subject, $this->body)) {
// Trigger a success notification
Notification::make()
->title('Email Sent')
->body('The email has been sent successfully.')
->send();
$this->to = '';
} else {
// Trigger an error notification
Notification::make()
->title('Email Not Sent')
->body('The email could not be sent.')
->send();
}
}
}

View file

@ -1,6 +1,6 @@
<x-filament-panels::page>
<div>
<div>
Email settings
</div>

View file

@ -0,0 +1,22 @@
<x-filament-panels::page>
<div>
<form wire:submit="send">
<div class="mb-4">
{{ $this->form }}
</div>
<x-filament::button
type="submit"
wire:loading.attr="disabled"
>
<span wire:loading.remove>Send</span>
<span wire:loading>Sending...</span>
</x-filament::button>
</form>
<x-filament-actions::modals />
</div>
</x-filament-panels::page>