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\Str;
|
2023-09-06 08:04:08 +00:00
|
|
|
use Illuminate\Support\Arr;
|
2023-10-27 08:18:08 +00:00
|
|
|
use Vinkla\Hashids\Facades\Hashids;
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
class SubmissionConfirmationMail extends OpenFormMail implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Queueable, SerializesModels;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new message instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(private FormSubmitted $event)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the message.
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
public function build()
|
|
|
|
{
|
|
|
|
$form = $this->event->form;
|
|
|
|
|
|
|
|
$formatter = (new FormSubmissionFormatter($form, $this->event->data))
|
|
|
|
->createLinks()
|
2024-01-31 11:21:28 +00:00
|
|
|
->outputStringsOnly()
|
|
|
|
->useSignedUrlForFiles();
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
return $this
|
2023-09-06 08:04:08 +00:00
|
|
|
->replyTo($this->getReplyToEmail($form->creator->email))
|
2022-09-20 19:59:52 +00:00
|
|
|
->from($this->getFromEmail(), $form->notification_sender)
|
|
|
|
->subject($form->notification_subject)
|
|
|
|
->markdown('mail.form.confirmation-submission-notification',[
|
|
|
|
'fields' => $formatter->getFieldsWithValue(),
|
|
|
|
'form' => $form,
|
2023-01-10 13:52:14 +00:00
|
|
|
'noBranding' => $form->no_branding,
|
2023-10-27 08:18:08 +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('@');
|
|
|
|
return $originalFromAddress->first(). '+' . time() . '@' . $originalFromAddress->last();
|
|
|
|
}
|
2023-09-06 08:04:08 +00:00
|
|
|
|
|
|
|
private function getReplyToEmail($default)
|
|
|
|
{
|
|
|
|
$replyTo = Arr::get((array)$this->event->form->notification_settings, 'confirmation_reply_to', null);
|
|
|
|
return $replyTo ?? $default;
|
|
|
|
}
|
2022-09-20 19:59:52 +00:00
|
|
|
}
|