44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Mail;
|
|
|
|
use App\Mail\GenericTemplateMail;
|
|
use App\Services\Email\EmailTemplateRenderer;
|
|
use App\Services\Email\EmailTemplateService;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class SendTemplateEmailJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $tries = 3;
|
|
public int $backoff = 30;
|
|
|
|
/**
|
|
* @param array<int, string> $to
|
|
*/
|
|
public function __construct(
|
|
public readonly string $scenario,
|
|
public readonly array $to,
|
|
public readonly array $data = [],
|
|
) {}
|
|
|
|
public function handle(EmailTemplateService $service, EmailTemplateRenderer $renderer): void
|
|
{
|
|
$template = $service->loadTemplate($this->scenario);
|
|
$rendered = $renderer->render($template, $this->data);
|
|
|
|
Mail::to($this->to)->send(new GenericTemplateMail(
|
|
$rendered['subject'],
|
|
$rendered['html'],
|
|
$template->mailConfig(),
|
|
$this->scenario,
|
|
));
|
|
}
|
|
}
|