63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Modules\MarketingAddon\App\Emails;
|
||
|
|
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Mail\Mailable;
|
||
|
|
use Illuminate\Mail\Mailables\Address;
|
||
|
|
use Illuminate\Mail\Mailables\Content;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
use Illuminate\Support\Facades\Config;
|
||
|
|
use Illuminate\Mail\Mailables\Envelope;
|
||
|
|
|
||
|
|
class DynamicMail extends Mailable
|
||
|
|
{
|
||
|
|
use Queueable, SerializesModels;
|
||
|
|
|
||
|
|
private $data;
|
||
|
|
private $template;
|
||
|
|
|
||
|
|
public function __construct($template, $data)
|
||
|
|
{
|
||
|
|
$this->data = $data;
|
||
|
|
$this->template = $template;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function envelope(): Envelope
|
||
|
|
{
|
||
|
|
return new Envelope(
|
||
|
|
from: new Address(
|
||
|
|
Config::get('mail.from.address'),
|
||
|
|
Config::get('mail.from.name')
|
||
|
|
),
|
||
|
|
subject: $this->template->subject,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function content(): Content
|
||
|
|
{
|
||
|
|
return new Content(
|
||
|
|
view: 'mail.dynamic-mail',
|
||
|
|
with: [
|
||
|
|
'content' => $this->buildHtml(),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function attachments(): array
|
||
|
|
{
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function buildHtml()
|
||
|
|
{
|
||
|
|
$message = $this->template->message;
|
||
|
|
|
||
|
|
foreach ($this->data as $key => $value) {
|
||
|
|
$message = str_replace('[' . $key . ']', $value, $message);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $message;
|
||
|
|
}
|
||
|
|
}
|