<?php
 namespace Module\Vendor\Mail; use Illuminate\Support\Facades\Mail; class MailUtil { public static function send($email, $subject, $template, $templateData = [], $emailUserName = null, $option = []) { if (!modstart_config('systemEmailEnable', false)) { return; } static $inited = false; if (!$inited) { $inited = true; $config = modstart_config(); config([ 'mail' => [ 'driver' => 'smtp', 'host' => $config->getWithEnv('systemEmailSmtpServer'), 'port' => $config->getWithEnv('systemEmailSmtpSsl', false) ? 465 : 25, 'encryption' => $config->getWithEnv('systemEmailSmtpSsl', false) ? 'ssl' : 'tls', 'from' => [ 'address' => $config->getWithEnv('systemEmailSmtpUser'), 'name' => $config->getWithEnv('systemEmailFromName', $config->getWithEnv('siteName') . ' @ ' . $config->getWithEnv('siteDomain')) ], 'username' => $config->getWithEnv('systemEmailSmtpUser'), 'password' => $config->getWithEnv('systemEmailSmtpPassword'), ] ]); } $view = 'theme.' . modstart_config('siteTemplate', 'default') . '.mail.' . $template; if (!view()->exists($view)) { $view = 'theme.default.mail.' . $template; if (!view()->exists($view)) { $view = 'module::Vendor.View.mail.' . $template; } } if (!view()->exists($view)) { throw new \Exception('mail view not found : ' . $view); } if (null === $emailUserName) { $emailUserName = $email; } Mail::send($view, $templateData, function ($message) use ($email, $emailUserName, $subject, $option) { $message->to($email, $emailUserName)->subject($subject); if (!empty($option['attachment'])) { foreach ($option['attachment'] as $filename => $path) { $message->attach($path, ['as' => $filename]); } } }); } } 