<?php

namespace App\Services;

use Illuminate\Support\Facades\Mail;
use App\Mail\TemplateMail;

class MailService
{
    /**
     * CI macro.sendmail 같은 역할
     * @param string|array $to
     */
    public function sendTemplate($to, string $subject, string $view, array $data = []): void
    {
        $toList = is_array($to) ? $to : [$to];

        foreach ($toList as $toEmail) {
            Mail::send($view, $data, function ($m) use ($toEmail, $subject) {
                $m->to($toEmail)->subject($subject);
            });
        }
    }
}
