Skip to content

Commit 242649a

Browse files
update
1 parent 285adb3 commit 242649a

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Modules\Email\App\Filament\Pages;
4+
5+
use Filament\Forms\Components\Placeholder;
6+
use Filament\Forms\Components\Textarea;
7+
use Filament\Forms\Components\TextInput;
8+
use Filament\Forms\Form;
9+
use Filament\Notifications\Notification;
10+
use Filament\Pages\Page;
11+
12+
class SendEmail extends Page
13+
{
14+
protected static ?string $navigationIcon = 'heroicon-o-paper-airplane';
15+
16+
protected static string $view = 'email::filament.pages.send-email';
17+
18+
protected static ?string $navigationGroup = 'Email';
19+
20+
protected static ?string $navigationLabel = 'Send Email';
21+
22+
protected static ?int $navigationSort = 2;
23+
24+
public $from = '';
25+
public $to = '';
26+
public $body = 'Hi,
27+
Welcome to your new account.
28+
';
29+
public $subject = 'Welcome';
30+
31+
public function form(Form $form): Form
32+
{
33+
$this->from = 'admin@';
34+
35+
return $form
36+
->schema([
37+
TextInput::make('from')
38+
->disabled()
39+
->columnSpanFull(),
40+
TextInput::make('to')
41+
->label('To')
42+
->required()
43+
->columnSpanFull(),
44+
TextInput::make('subject')
45+
->label('Subject')
46+
->required()
47+
->columnSpanFull(),
48+
Textarea::make('body')
49+
->rows(10)
50+
->label('Body')
51+
->required()
52+
->columnSpanFull(),
53+
]);
54+
}
55+
56+
public function send()
57+
{
58+
if (mail($this->to, $this->subject, $this->body)) {
59+
// Trigger a success notification
60+
Notification::make()
61+
->title('Email Sent')
62+
->body('The email has been sent successfully.')
63+
->send();
64+
$this->to = '';
65+
} else {
66+
// Trigger an error notification
67+
Notification::make()
68+
->title('Email Not Sent')
69+
->body('The email could not be sent.')
70+
->send();
71+
}
72+
}
73+
}

web/Modules/Email/resources/views/filament/pages/email-settings.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<x-filament-panels::page>
22

3-
<div>
3+
<div>
44
Email settings
55
</div>
66

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<x-filament-panels::page>
2+
3+
<div>
4+
<form wire:submit="send">
5+
6+
<div class="mb-4">
7+
{{ $this->form }}
8+
</div>
9+
10+
<x-filament::button
11+
type="submit"
12+
wire:loading.attr="disabled"
13+
>
14+
<span wire:loading.remove>Send</span>
15+
<span wire:loading>Sending...</span>
16+
</x-filament::button>
17+
</form>
18+
19+
<x-filament-actions::modals />
20+
</div>
21+
22+
</x-filament-panels::page>

0 commit comments

Comments
 (0)