|
|
@@ -0,0 +1,45 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Services ; |
|
|
|
|
|
|
|
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; |
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
|
use Twig\Environment; |
|
|
|
|
|
|
|
class MailUtils |
|
|
|
{ |
|
|
|
const SUBJECT = 'subject' ; |
|
|
|
const TO_EMAIL = 'to-email' ; |
|
|
|
const TO_NAME = 'to-name' ; |
|
|
|
const FROM_EMAIL = 'from-email' ; |
|
|
|
const FROM_NAME = 'from-name' ; |
|
|
|
const CONTENT_TEMPLATE = 'content-template' ; |
|
|
|
const CONTENT_DATA = 'content-data' ; |
|
|
|
|
|
|
|
protected $transport ; |
|
|
|
protected $templating ; |
|
|
|
protected $parameterBag ; |
|
|
|
|
|
|
|
public function __construct(MailjetTransport $mailjetTransport, Environment $templating,ParameterBagInterface $parameterBag) |
|
|
|
{ |
|
|
|
$this->transport = $mailjetTransport ; |
|
|
|
$this->templating = $templating ; |
|
|
|
$this->parameterBag = $parameterBag ; |
|
|
|
} |
|
|
|
|
|
|
|
public function send($params = []) |
|
|
|
{ |
|
|
|
$message = new \Swift_Message($params[self::SUBJECT]); |
|
|
|
$message->addTo( |
|
|
|
$params[self::TO_EMAIL], |
|
|
|
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null) |
|
|
|
->addFrom( |
|
|
|
isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $this->parameterBag->get('app.noreply_email'), |
|
|
|
isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $this->parameterBag->get('app.site_name')) |
|
|
|
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE].'-html.html.twig', $params[self::CONTENT_DATA]), 'text/html') |
|
|
|
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE].'-text.html.twig', $params[self::CONTENT_DATA])) |
|
|
|
; |
|
|
|
|
|
|
|
$this->transport->send($message) ; |
|
|
|
} |
|
|
|
} |