ldc-boutique-cnc-sable/app/Mail/SendContactMail.php

98 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2021-04-06 12:56:54 +02:00
<?php
2026-06-14 21:32:07 +02:00
declare(strict_types=1);
2021-04-06 12:56:54 +02:00
namespace App\Mail;
2026-06-14 21:32:07 +02:00
use Domain\Models\ValueObjects\ContactFormData;
2021-04-06 12:56:54 +02:00
use Illuminate\Bus\Queueable;
2026-06-14 21:32:07 +02:00
use Illuminate\Contracts\Queue\ShouldQueue;
2021-04-06 12:56:54 +02:00
use Illuminate\Mail\Mailable;
2026-06-14 21:32:07 +02:00
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
2021-04-06 12:56:54 +02:00
use Illuminate\Queue\SerializesModels;
2026-06-14 21:32:07 +02:00
use Illuminate\Support\Facades\Config;
2021-04-06 12:56:54 +02:00
2026-06-14 21:32:07 +02:00
// NOTE: This may be be queued
class SendContactMail extends Mailable implements ShouldQueue
2021-04-06 12:56:54 +02:00
{
use Queueable;
use SerializesModels;
2026-06-14 21:32:07 +02:00
/** 'failed_jobs' after */
public int $tries = 5;
2021-04-06 12:56:54 +02:00
/**
2026-06-14 21:32:07 +02:00
* Attempts delays
2021-04-06 12:56:54 +02:00
*
2026-06-14 21:32:07 +02:00
* @return array<int, int>
2021-04-06 12:56:54 +02:00
*/
2026-06-14 21:32:07 +02:00
public function backoff(): array
{
return [10, 30, 60, 300];
}
2021-04-06 12:56:54 +02:00
/**
2026-06-14 21:32:07 +02:00
* Create a new message instance.
2021-04-06 12:56:54 +02:00
*/
2026-06-14 21:32:07 +02:00
public function __construct(
public readonly ContactFormData $data
) {
}
2021-04-06 12:56:54 +02:00
/**
2026-06-14 21:32:07 +02:00
* Get the message envelope.
2021-04-06 12:56:54 +02:00
*/
2026-06-14 21:32:07 +02:00
public function envelope(): Envelope
2021-04-06 12:56:54 +02:00
{
2026-06-14 21:32:07 +02:00
return new Envelope(
subject: trans('Contact') .
' - ' . Config::string('app.name') .
' - ' . e($this->data->subject),
replyTo: [
new Address(
$this->data->email,
$this->data->firstName . ' ' . $this->data->lastName
),
],
);
2021-04-06 12:56:54 +02:00
}
/**
2026-06-14 21:32:07 +02:00
* Get the message content definition.
2021-04-06 12:56:54 +02:00
*/
2026-06-14 21:32:07 +02:00
public function content(): Content
2021-04-06 12:56:54 +02:00
{
2026-06-14 21:32:07 +02:00
return new Content(
markdown: 'emails.send-contact',
);
2021-04-06 12:56:54 +02:00
}
/**
2026-06-14 21:32:07 +02:00
* Get the attachments for the message.
2021-04-06 12:56:54 +02:00
*
2026-06-14 21:32:07 +02:00
* @return \Illuminate\Mail\Mailables\Attachment[]
2021-04-06 12:56:54 +02:00
*/
2026-06-14 21:32:07 +02:00
public function attachments(): array
2021-04-06 12:56:54 +02:00
{
2026-06-14 21:32:07 +02:00
if ($this->data->file === null) {
return [];
2021-04-06 12:56:54 +02:00
}
2026-06-14 21:32:07 +02:00
$extension = pathinfo($this->data->file->originalName, PATHINFO_EXTENSION);
$joinedFileName = sprintf(
'BOUTIQUE_MESSAGE-PJ-%s.%s',
date('YmdHis'),
$extension
);
return [
Attachment::fromPath($this->data->file->path)
->as($joinedFileName)
->withMime($this->data->file->mimeType),
];
2021-04-06 12:56:54 +02:00
}
}