-
app/Mail/Forms/SubmissionConfirmationMail.php
Open in GitHubuse App\Events\Forms\FormSubmitted; use App\Mail\OpenFormMail; use App\Service\Forms\FormSubmissionFormatter; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Str; class SubmissionConfirmationMail extends OpenFormMail implements ShouldQueue { use Queueable, SerializesModels; public function __construct(private FormSubmitted $event) {} public function build() { $form = $this->event->form; $formatter = (new FormSubmissionFormatter($form, $this->event->data)) ->createLinks() ->outputStringsOnly(); return $this ->replyTo($form->creator->email) ->from($this->getFromEmail(), $form->notification_sender) ->subject($form->notification_subject) ->markdown('mail.form.confirmation-submission-notification',[ 'fields' => $formatter->getFieldsWithValue(), 'form' => $form, 'noBranding' => $form->no_branding ]); } private function getFromEmail() { $originalFromAddress = Str::of(config('mail.from.address'))->explode('@'); return $originalFromAddress->first(). '+' . time() . '@' . $originalFromAddress->last(); } }
-
resources/views/mail/form/confirmation-submission-notification.blade.php
Open in GitHub@component('mail::message', ['noBranding' => $noBranding]) {!! $form->notification_body !!} @if($form->notifications_include_submission) As a reminder, here are your answers: @foreach($fields as $field) @if(isset($field['value'])) -------------------------------------------------------------------------------- **{{$field['name']}}** {!! is_array($field['value'])?implode(',',$field['value']):$field['value']!!} @endif @endforeach @endif <p style="text-align:center"><small>You are receiving this email because you answered the form: <a href="{{url("forms/".$form->slug)}}">"{{$form->title}}"</a>.</small></p> @endcomponent
-
app/Listeners/Forms/SubmissionConfirmation.php
Open in GitHubuse App\Events\Forms\FormSubmitted; use App\Mail\Forms\SubmissionConfirmationMail; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Support\Facades\Mail; class SubmissionConfirmation implements ShouldQueue { use InteractsWithQueue; public function handle(FormSubmitted $event) { if (!$event->form->send_submission_confirmation) return; $email = $this->getRespondentEmail($event); if (!$email) return; \Log::info('Sending submission confirmation',[ 'recipient' => $email, 'form_id' => $event->form->id, 'form_slug' => $event->form->slug, ]); Mail::to($email)->send(new SubmissionConfirmationMail($event)); } private function getRespondentEmail(FormSubmitted $event) { // Make sure we only have one email field in the form $emailFields = collect($event->form->properties)->filter(function($field) { $hidden = $field['hidden']?? false; return !$hidden && $field['type'] == 'email'; }); if ($emailFields->count() != 1) return null; if (isset($event->data[$emailFields->first()['id']])) { $email = $event->data[$emailFields->first()['id']]; if ($this->validateEmail($email)) return $email; } return null; } public static function validateEmail($email): bool { return (boolean) filter_var($email, FILTER_VALIDATE_EMAIL); } }