60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Mail;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Mail\Mailables\Attachment;
|
|
use Illuminate\Mail\Mailables\Content;
|
|
use Illuminate\Mail\Mailables\Envelope;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class ContactNotification extends Mailable
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* @param array<string, mixed> $data
|
|
* @param array{name: string, mime: string, content: string}|null $attachment
|
|
*/
|
|
public function __construct(
|
|
public readonly array $data,
|
|
public readonly ?array $attachment = null,
|
|
) {
|
|
}
|
|
|
|
public function envelope(): Envelope
|
|
{
|
|
return new Envelope(
|
|
subject: 'Nouveau message - Formulaire de contact',
|
|
);
|
|
}
|
|
|
|
public function content(): Content
|
|
{
|
|
return new Content(
|
|
view: 'emails.contact',
|
|
with: ['data' => $this->data],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<int, Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
if ($this->attachment === null) {
|
|
return [];
|
|
}
|
|
|
|
return [
|
|
Attachment::fromData(
|
|
fn () => base64_decode($this->attachment['content']),
|
|
$this->attachment['name'],
|
|
)->withMime($this->attachment['mime']),
|
|
];
|
|
}
|
|
}
|