ldc-boutique-cnc-sable/app/Mail/SendContactMail.php
2026-10-27 09:58:12 +01:00

97 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Mail;
use Domain\Models\ValueObjects\ContactFormData;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
// NOTE: This may be be queued
class SendContactMail extends Mailable implements ShouldQueue
{
use Queueable;
use SerializesModels;
/** 'failed_jobs' after */
public int $tries = 5;
/**
* Attempts delays
*
* @return array<int, int>
*/
public function backoff(): array
{
return [10, 30, 60, 300];
}
/**
* Create a new message instance.
*/
public function __construct(
public readonly ContactFormData $data
) {
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
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
),
],
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'emails.send-contact',
);
}
/**
* Get the attachments for the message.
*
* @return \Illuminate\Mail\Mailables\Attachment[]
*/
public function attachments(): array
{
if ($this->data->file === null) {
return [];
}
$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),
];
}
}