76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Http\Requests\ContactFormRequest;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class SendContactMail extends Mailable
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The form data.
|
|
*
|
|
* @var \App\Http\Requests\ContactFormRequest
|
|
*/
|
|
protected $data;
|
|
|
|
/**
|
|
* The joined file name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $joinedFileName;
|
|
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \App\Http\Requests\ContactFormRequest $data
|
|
* @return void
|
|
*/
|
|
public function __construct(ContactFormRequest $data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
$data = $this->data;
|
|
$this->joinFileIfProvided();
|
|
|
|
return $this->subject("Contact - " . config('theme.site_name', 'Boutique') . " - " . $data->subject)
|
|
->from($data->email)
|
|
->view('mails.send-contact', compact('data'));
|
|
}
|
|
|
|
|
|
/**
|
|
* Attach a joined file if given in data
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function joinFileIfProvided(): void
|
|
{
|
|
if ($this->data->file) {
|
|
$this->joinedFileName = sprintf(
|
|
'BOUTIQUE_MESSAGE-PJ-%s.%s',
|
|
date("YmdHis"),
|
|
$this->data->file->extension()
|
|
);
|
|
$this->attach($this->data->file, [
|
|
'as' => $this->joinedFileName,
|
|
'mime' => $this->data->file->getMimeType()
|
|
]);
|
|
}
|
|
}
|
|
}
|