ldc-cocotte/app/Mail/SendContactMail.php

80 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Mail;
use App\Lib\PrivateS3Disk;
use Domain\Models\ValueObjects\ContactFormData;
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\Support\Facades\Config;
class SendContactMail extends Mailable
{
/**
* 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
);
$disk = app()->make(PrivateS3Disk::class)->disk->value;
return [
Attachment::fromStorageDisk($disk, $this->data->file->path)
->as($joinedFileName)
->withMime($this->data->file->mimeType),
];
}
}