diff --git a/app/Filament/Admin/Resources/PermResource.php b/app/Filament/Admin/Resources/PermResource.php index 750413e..bcf74b1 100644 --- a/app/Filament/Admin/Resources/PermResource.php +++ b/app/Filament/Admin/Resources/PermResource.php @@ -192,6 +192,7 @@ public static function form(Form $form): Form ->placeholder('Adresse mail du responsable de la permanence') ->label('Adresse mail du responsable') ->default(auth()->user()?->email) + ->email() ->columnSpan([ 'sm' => 6, 'md' => 4, @@ -214,6 +215,7 @@ public static function form(Form $form): Form ->required() ->placeholder('Adresse mail du sous-responsable') ->label('Adresse mail du sous-responsable') + ->email() ->columnSpan([ 'sm' => 6, 'md' => 4, @@ -237,6 +239,7 @@ public static function form(Form $form): Form ->required(fn(Forms\Get $get) => $get('asso')) ->placeholder('Adresse mail de l\'association') ->label('Adresse mail de l\'association') + ->email() ->columnSpan([ 'sm' => 6, 'md' => 6, @@ -484,12 +487,33 @@ public static function sendMail($record) return; } + // Vérification : l'email du responsable est-il valide? + if (!filter_var($record->mail_resp, FILTER_VALIDATE_EMAIL)) { + \Filament\Notifications\Notification::make() + ->title('Erreur : Email invalide') + ->body('Impossible d\'envoyer le mail car l\'email du responsable est invalide.') + ->danger() + ->send(); + return; + } + DB::beginTransaction(); try { $mailResp1 = $record->mail_resp; $mailResp2 = $record->mail_resp_2; $mailAsso = $record->mail_asso; + $incorrectEmails = []; + + // Vérification : les emails sont-ils valides ? + if($mailResp2 && !filter_var($mailResp2, FILTER_VALIDATE_EMAIL)) { + $incorrectEmails[] = $mailResp2; + $mailResp2 = null; + } + if($mailAsso && !filter_var($mailAsso, FILTER_VALIDATE_EMAIL)) { + $incorrectEmails[] = $mailAsso; + $mailAsso = null; + } $email = Mail::to($mailResp1); if ($mailResp2 && $mailAsso) { @@ -516,10 +540,19 @@ public static function sendMail($record) DB::commit(); - \Filament\Notifications\Notification::make() + if(!empty($incorrectEmails)) { + \Filament\Notifications\Notification::make() + ->title('Mail envoyé avec succès') + ->body('Sauf pour les adresses suivantes : ' . implode(', ', $incorrectEmails)) + ->success() + ->send(); + } else { + \Filament\Notifications\Notification::make() ->title('Mail envoyé avec succès') ->success() ->send(); + } + } catch (Exception $e) { DB::rollBack(); \Filament\Notifications\Notification::make() diff --git a/app/Filament/Public/Resources/RequestedPermsResource.php b/app/Filament/Public/Resources/RequestedPermsResource.php index e15c475..bee1794 100644 --- a/app/Filament/Public/Resources/RequestedPermsResource.php +++ b/app/Filament/Public/Resources/RequestedPermsResource.php @@ -187,6 +187,7 @@ public static function form(Form $form): Form ->placeholder('Adresse mail du responsable de la permanence') ->label('Adresse mail du responsable') ->default(auth()->user()?->email) + ->email() ->columnSpan([ 'sm' => 6, 'md' => 4, @@ -209,6 +210,7 @@ public static function form(Form $form): Form ->required() ->placeholder('Adresse mail du sous-responsable') ->label('Adresse mail du sous-responsable') + ->email() ->columnSpan([ 'sm' => 6, 'md' => 4, @@ -232,6 +234,7 @@ public static function form(Form $form): Form ->required(fn (Forms\Get $get) => $get('asso')) ->placeholder('Adresse mail de l\'association') ->label('Adresse mail de l\'association') + ->email() ->columnSpan([ 'sm' => 6, 'md' => 6,