86 lines
2 KiB
PHP
86 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\Contact;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class SendContactMail extends Mailable
|
|
{
|
|
use Queueable;
|
|
use SerializesModels;
|
|
|
|
/**
|
|
* The contact data
|
|
*
|
|
* @var \App\Models\Contact
|
|
*/
|
|
protected $contact;
|
|
|
|
/**
|
|
* The joined file name
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $joinedFileName;
|
|
|
|
|
|
/**
|
|
* Create a new message instance.
|
|
*
|
|
* @param \App\Models\Contact $contact
|
|
* @return void
|
|
*/
|
|
public function __construct(Contact $contact)
|
|
{
|
|
$this->contact = $contact;
|
|
}
|
|
|
|
/**
|
|
* Build the message.
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function build()
|
|
{
|
|
$data = $this->contact;
|
|
$this->joinFileIfProvided();
|
|
|
|
return $this->subject('Contact - ' . config('theme.site_name', 'Boutique') . " - " . $data->subject)
|
|
->from($data->email)
|
|
->markdown('back::emails.send-contact', compact('data'));
|
|
}
|
|
|
|
|
|
/**
|
|
* Attach a joined file if given in data
|
|
*
|
|
* @return void
|
|
* @throws \RuntimeException If the mimetype cannot be guessed.
|
|
*/
|
|
protected function joinFileIfProvided(): void
|
|
{
|
|
if ($this->contact->file and File::exists($this->contact->file)) {
|
|
$extension = File::guessExtension($this->contact->file) ??
|
|
File::extension($this->contact->file);
|
|
$mimeType = File::mimeType($this->contact->file);
|
|
|
|
if (!$mimeType) {
|
|
throw new \RuntimeException('Could not guess joined file mimetype');
|
|
}
|
|
|
|
$this->joinedFileName = sprintf(
|
|
'BOUTIQUE_MESSAGE-PJ-%s.%s',
|
|
date("YmdHis"),
|
|
$extension
|
|
);
|
|
$this->attach($this->contact->file, [
|
|
'as' => $this->joinedFileName,
|
|
'mime' => $mimeType
|
|
]);
|
|
}
|
|
}
|
|
}
|