opnform/app/Mail/Forms/SubmissionConfirmationMail.php

72 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2022-09-20 19:59:52 +00:00
<?php
namespace App\Mail\Forms;
use 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\Arr;
2024-02-23 10:54:12 +00:00
use Illuminate\Support\Str;
use Vinkla\Hashids\Facades\Hashids;
2022-09-20 19:59:52 +00:00
class SubmissionConfirmationMail extends OpenFormMail implements ShouldQueue
{
2024-02-23 10:54:12 +00:00
use Queueable;
use SerializesModels;
2022-09-20 19:59:52 +00:00
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(private FormSubmitted $event)
2024-02-23 10:54:12 +00:00
{
}
2022-09-20 19:59:52 +00:00
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$form = $this->event->form;
$formatter = (new FormSubmissionFormatter($form, $this->event->data))
->createLinks()
->outputStringsOnly()
->useSignedUrlForFiles();
2022-09-20 19:59:52 +00:00
return $this
->replyTo($this->getReplyToEmail($form->creator->email))
2022-09-20 19:59:52 +00:00
->from($this->getFromEmail(), $form->notification_sender)
->subject($form->notification_subject)
2024-02-23 10:54:12 +00:00
->markdown('mail.form.confirmation-submission-notification', [
2022-09-20 19:59:52 +00:00
'fields' => $formatter->getFieldsWithValue(),
'form' => $form,
'noBranding' => $form->no_branding,
2024-02-23 10:54:12 +00:00
'submission_id' => (isset($this->event->data['submission_id']) && $this->event->data['submission_id']) ? Hashids::encode($this->event->data['submission_id']) : null,
2022-09-20 19:59:52 +00:00
]);
}
private function getFromEmail()
{
$originalFromAddress = Str::of(config('mail.from.address'))->explode('@');
2024-02-23 10:54:12 +00:00
return $originalFromAddress->first().'+'.time().'@'.$originalFromAddress->last();
2022-09-20 19:59:52 +00:00
}
private function getReplyToEmail($default)
{
2024-02-23 10:54:12 +00:00
$replyTo = Arr::get((array) $this->event->form->notification_settings, 'confirmation_reply_to', null);
if ($replyTo && filter_var($replyTo, FILTER_VALIDATE_EMAIL)) {
return $replyTo;
}
return $default;
}
2022-09-20 19:59:52 +00:00
}