fix email reply to issue (#326)

* fix email reply to issue

* fix: email  test  issue

* fix: phpunit  file

* style: fix lint
This commit is contained in:
Favour Olayinka 2024-02-27 15:20:50 +01:00 committed by GitHub
parent 7c90ed58bd
commit 8a067012e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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
});