Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Lc\ShopBundle\Services;
  3. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  4. use Lc\ShopBundle\Model\Merchant;
  5. use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
  6. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  7. use Twig\Environment;
  8. class MailUtils
  9. {
  10. const SUBJECT = 'subject';
  11. const SUBJECT_PREFIX = 'subject-prefix';
  12. const TO_EMAIL = 'to-email';
  13. const COPY_TO = 'copy-to';
  14. const COPY_HIDDEN_TO = 'copy-hidden-to';
  15. const TO_NAME = 'to-name';
  16. const FROM_EMAIL = 'from-email';
  17. const FROM_NAME = 'from-name';
  18. const REPLY_TO = 'reply-to';
  19. const CONTENT_TEMPLATE = 'content-template';
  20. const CONTENT_DATA = 'content-data';
  21. const ATTACHMENT_DATA = 'attachment-data';
  22. const ATTACHMENT_FILENAME = 'attachment-filename';
  23. const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type';
  24. //const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ;
  25. protected $transport;
  26. protected $templating;
  27. protected $parameterBag;
  28. protected $merchantUtils;
  29. public function __construct(
  30. MailjetTransport $mailjetTransport,
  31. Environment $templating,
  32. ParameterBagInterface $parameterBag,
  33. MerchantUtilsInterface $merchantUtils
  34. ) {
  35. $this->transport = $mailjetTransport;
  36. $this->templating = $templating;
  37. $this->parameterBag = $parameterBag;
  38. $this->merchantUtils = $merchantUtils;
  39. }
  40. public function send($params = [])
  41. {
  42. $merchantCurrent = $this->merchantUtils->getMerchantCurrent();
  43. $merchantConfigEmailFrom = $merchantCurrent->getMerchantConfig('email-from');
  44. $emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;
  45. $merchantConfigEmailFromName = $merchantCurrent->getMerchantConfig('email-from-name');
  46. $emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName;
  47. $merchantConfigEmailSubjectPrefix = $merchantCurrent->getMerchantConfig('email-subject-prefix');
  48. $emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix;
  49. if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
  50. $emailSubjectPrefix .= ' ';
  51. }
  52. $message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]);
  53. if ($this->parameterBag->get('mailjet.dev.redirect.active')==1) {
  54. $message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'),
  55. isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
  56. } else {
  57. $message->addTo(
  58. $params[self::TO_EMAIL],
  59. isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
  60. }
  61. $contentData = [] ;
  62. if(isset($params[self::CONTENT_DATA])) {
  63. $contentData = $params[self::CONTENT_DATA] ;
  64. }
  65. $message->addFrom($emailFrom, $emailFromName)
  66. ->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html')
  67. ->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData));
  68. if(isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) {
  69. $message->addCc($params[self::COPY_TO]);
  70. }
  71. if(isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) {
  72. $message->addBcc($params[self::COPY_HIDDEN_TO]);
  73. }
  74. if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) {
  75. $message->addReplyTo($params[self::REPLY_TO]);
  76. }
  77. if(isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) {
  78. $message->attach(\Swift_Attachment::newInstance(
  79. $params[self::ATTACHMENT_DATA],
  80. $params[self::ATTACHMENT_FILENAME],
  81. $params[self::ATTACHMENT_CONTENT_TYPE]
  82. ));
  83. }
  84. /*if(isset($params[self::DISPOSITION_NOTIFICATION_TO]) && $params[self::DISPOSITION_NOTIFICATION_TO]) {
  85. $emailFromDispositionNotificationTo = $emailFrom ;
  86. if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) {
  87. $emailFromDispositionNotificationTo = $params[self::REPLY_TO] ;
  88. }
  89. $message->getHeaders()->addTextHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo) ;
  90. $message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo);
  91. }*/
  92. $this->transport->send($message);
  93. }
  94. }