110 lines
3.5 KiB
PHP
110 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Enums\Contact\ObjectEnum;
|
|
use Illuminate\Bus\Queueable;
|
|
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;
|
|
|
|
class SendContactMail extends Mailable
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* @var \App\Mail\Contact
|
|
*/
|
|
private \stdClass $data;
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \stdClass $data
|
|
* @return void
|
|
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
|
*/
|
|
public function __construct(\stdClass $data)
|
|
{
|
|
$this->data = clone $data;
|
|
}
|
|
|
|
/**
|
|
* Get the message envelope.
|
|
*
|
|
* @return \Illuminate\Mail\Mailables\Envelope
|
|
*/
|
|
public function envelope(): \Illuminate\Mail\Mailables\Envelope
|
|
{
|
|
return new Envelope(
|
|
from: new Address(
|
|
$this->data->email,
|
|
($this->data->first_name !== null || $this->data->last_name !== null) ?
|
|
(($this->data->first_name ?? '') . " " . ($this->data->last_name ?? '')) :
|
|
null
|
|
),
|
|
to: [new Address(config('mail.from.address'), config('mail.from.name'))],
|
|
subject: sprintf('%s - %s', ObjectEnum::make($this->data->object)->label() ?? __('Nouveau message'), config('app.name')),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the message content definition.
|
|
*
|
|
* @return \Illuminate\Mail\Mailables\Content
|
|
*/
|
|
public function content(): \Illuminate\Mail\Mailables\Content
|
|
{
|
|
return new Content(
|
|
markdown: 'emails.send-contact-form',
|
|
with: ['data' => $this->data],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get the attachments for the message.
|
|
*
|
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
|
*/
|
|
public function attachments(): array
|
|
{
|
|
$attachments = [];
|
|
if (isset($this->data->file)) {
|
|
$attachments[] = Attachment::fromPath($this->data->file->getRealPath())
|
|
->as($this->data->file->getClientOriginalName())
|
|
->withMime($this->data->file->getClientMimeType());
|
|
}
|
|
return $attachments;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @property integer $civility
|
|
* @property string $last_name
|
|
* @property string $first_name
|
|
* @property string $society
|
|
* @property string $email
|
|
* @property string $phone
|
|
* @property string $address
|
|
* @property string $postal_code
|
|
* @property boolean $city
|
|
* @property integer $object
|
|
* @property string $message
|
|
* @property string $product_name
|
|
* @property string $product_date_limit
|
|
* @property string $product_barcode
|
|
* @property string $product_lot
|
|
* @property string $product_date_consumption
|
|
* @property string $product_location
|
|
* @property boolean $accept_rules
|
|
* @property boolean $send_data
|
|
* @property \Illuminate\Http\UploadedFile $file
|
|
* @phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
|
|
*/
|
|
class Contact extends \stdClass
|
|
{
|
|
}
|