ldc-cocotte/app/Mail/SendContactMail.php

81 lines
1.9 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;
use App\Lib\PrivateS3Disk;
2026-06-14 21:32:07 +02:00
use Domain\Models\ValueObjects\ContactFormData;
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;
use Illuminate\Support\Facades\Config;
2021-04-06 12:56:54 +02:00
class SendContactMail extends Mailable
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
);
$disk = app()->make(PrivateS3Disk::class)->disk->value;
2026-06-14 21:32:07 +02:00
return [
Attachment::fromStorageDisk($disk, $this->data->file->path)
2026-06-14 21:32:07 +02:00
->as($joinedFileName)
->withMime($this->data->file->mimeType),
];
2021-04-06 12:56:54 +02:00
}
}