From 8a067012e5b51dc612593cb8bc2aeb744cb769cb Mon Sep 17 00:00:00 2001 From: Favour Olayinka Date: Tue, 27 Feb 2024 15:20:50 +0100 Subject: [PATCH] fix email reply to issue (#326) * fix email reply to issue * fix: email test issue * fix: phpunit file * style: fix lint --- app/Mail/Forms/SubmissionConfirmationMail.php | 5 +++- tests/Feature/Forms/ConfirmationEmailTest.php | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Mail/Forms/SubmissionConfirmationMail.php b/app/Mail/Forms/SubmissionConfirmationMail.php index 93a82ef..52ec21f 100644 --- a/app/Mail/Forms/SubmissionConfirmationMail.php +++ b/app/Mail/Forms/SubmissionConfirmationMail.php @@ -63,6 +63,9 @@ class SubmissionConfirmationMail extends OpenFormMail implements ShouldQueue { $replyTo = Arr::get((array) $this->event->form->notification_settings, 'confirmation_reply_to', null); - return $replyTo ?? $default; + if ($replyTo && filter_var($replyTo, FILTER_VALIDATE_EMAIL)) { + return $replyTo; + } + return $default; } } diff --git a/tests/Feature/Forms/ConfirmationEmailTest.php b/tests/Feature/Forms/ConfirmationEmailTest.php index 6776b7b..8e03a69 100644 --- a/tests/Feature/Forms/ConfirmationEmailTest.php +++ b/tests/Feature/Forms/ConfirmationEmailTest.php @@ -110,3 +110,31 @@ it('does not send a confirmation email if not needed', function () { } ); }); + +it('does send a confirmation email even when reply to is broken', function () { + $user = $this->actingAsProUser(); + $workspace = $this->createUserWorkspace($user); + $form = $this->createForm($user, $workspace, [ + 'send_submission_confirmation' => true, + 'notifications_include_submission' => true, + 'notification_sender' => 'Custom Sender', + 'notification_subject' => 'Test subject', + 'notification_body' => 'Test body', + 'notification_settings' => [ + 'confirmation_reply_to' => 'invalid-email', + ] + ]); + + $emailProperty = collect($form->properties)->first(function ($property) { + return $property['type'] == 'email'; + }); + $formData = [ + $emailProperty['id'] => 'test@test.com', + ]; + $event = new \App\Events\Forms\FormSubmitted($form, $formData); + $mailable = new SubmissionConfirmationMail($event); + $mailable->assertSeeInHtml('Test body') + ->assertSeeInHtml('As a reminder, here are your answers:') + ->assertSeeInHtml('You are receiving this email because you answered the form:') + ->assertHasReplyTo($user->email); // Even though reply to is wrong, it should use the user's email +});