ldc-doux/app/Mail/SendContactMail.php

106 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2021-12-01 09:01:04 +01:00
<?php
/**
* Sender pour le contact
*
2021-12-01 09:01:04 +01:00
* @category Description
* @package Category
* @author Name <email@email.com>
* @license http://url.com MIT
* @link http://url.com
* phpcs:ignore PEAR.Commenting.FileComment.MissingVersion
*/
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
/**
* Undocumented class
*
2021-12-01 09:01:04 +01:00
* @category Description
* @package Category
* @author Name <email@email.com>
* @license http://url.com MIT
* @link http://url.com
*/
class SendContactMail extends Mailable
{
use Queueable;
use SerializesModels;
/**
* The form data.
2022-08-29 17:23:10 +02:00
*
* @var array
2021-12-01 09:01:04 +01:00
*/
protected $data;
/**
* The joined file name
*
* @var string
*/
protected $joinedFileName;
/**
* Create a new message instance.
*
2022-08-29 17:23:10 +02:00
* @param array $data
*
2021-12-01 09:01:04 +01:00
* @return void
*/
2022-08-29 17:23:10 +02:00
public function __construct(array $data)
2021-12-01 09:01:04 +01:00
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$data = $this->data;
$this->joinFileIfProvided();
return $this->subject(
"Contact - " .
config('app.name', 'Doux') .
" - " .
2022-05-19 11:32:54 +02:00
$data['topic']
2021-12-01 09:01:04 +01:00
)
2022-05-19 11:32:54 +02:00
->from($data['email'])
2021-12-01 09:01:04 +01:00
->view('emails.send-contact', compact('data'));
}
/**
* Attach a joined file if given in data
*
* @return void
*/
protected function joinFileIfProvided(): void
{
2022-05-19 11:32:54 +02:00
if (isset($this->data['file'])) {
2021-12-01 09:01:04 +01:00
$this->joinedFileName = sprintf(
'Doux_MESSAGE-PJ-%s.%s',
date("YmdHis"),
2022-05-19 11:32:54 +02:00
$this->data['file']->extension()
2021-12-01 09:01:04 +01:00
);
$this->attach(
2022-05-19 11:32:54 +02:00
$this->data['file'],
2021-12-01 09:01:04 +01:00
[
'as' => $this->joinedFileName,
2022-05-19 11:32:54 +02:00
'mime' => $this->data['file']->getMimeType()
2021-12-01 09:01:04 +01:00
]
);
2022-05-19 11:32:54 +02:00
$this->data['file'] = $this->joinedFileName;
2021-12-01 09:01:04 +01:00
}
}
}