You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GeekQu_sspanel/app/Services/Mail.php

71 lines
1.7 KiB
PHTML

9 years ago
<?php
namespace App\Services;
/***
* Mail Service
*/
use App\Services\Mail\Mailgun;
use App\Services\Mail\Ses;
use App\Services\Mail\Smtp;
use App\Services\Mail\SendGrid;
use App\Services\Mail\NullMail;
use Smarty;
class Mail
{
/**
* @return Mailgun|NullMail|SendGrid|Ses|Smtp|null
9 years ago
*/
public static function getClient()
{
$driver = Config::get('mailDriver');
9 years ago
switch ($driver) {
case 'mailgun':
9 years ago
return new Mailgun();
case 'ses':
9 years ago
return new Ses();
case 'smtp':
9 years ago
return new Smtp();
case 'sendgrid':
9 years ago
return new SendGrid();
default:
return new NullMail();
}
}
/**
* @param $template
* @param $ary
* @return mixed
*/
public static function genHtml($template, $ary)
{
$smarty = new smarty();
$smarty->settemplatedir(BASE_PATH . '/resources/email/');
$smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/');
$smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/');
// add config
$smarty->assign('config', Config::getPublicConfig());
foreach ($ary as $key => $value) {
$smarty->assign($key, $value);
}
return $smarty->fetch($template);
}
/**
* @param $to
* @param $subject
* @param $template
* @param $ary
* @param $files
9 years ago
* @return bool|void
*/
public static function send($to, $subject, $template, $ary = [], $files = [])
9 years ago
{
$text = self::genHtml($template, $ary);
return self::getClient()->send($to, $subject, $text, $files);
9 years ago
}
}