vendor/uvdesk/core-framework/Services/EmailService.php line 555

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Services;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity\EmailTemplates;
  9. use Symfony\Component\DependencyInjection\ContainerInterface;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. class EmailService
  13. {
  14.     private $request;
  15.     private $container;
  16.     private $entityManager;
  17.     private $session;
  18.     public function __construct(ContainerInterface $containerRequestStack $requestEntityManagerInterface $entityManagerSessionInterface $session)
  19.     {
  20.         $this->request $request;
  21.         $this->container $container;
  22.         $this->entityManager $entityManager;
  23.         $this->session $session;
  24.     }
  25.     public function trans($text)
  26.     {
  27.         return $this->container->get('translator')->trans($text);
  28.     }
  29.     public function getEmailPlaceHolders($params)
  30.     {
  31.         $placeHolders = [];
  32.         $allEmailPlaceholders = [];
  33.         $template is_array($params) ? ($params['match'] . 'Note') : (!empty($params) ? $params 'template');
  34.         if ($template == 'template') {
  35.             $placeHolders = [
  36.                 'ticket' => [
  37.                     'id' => [
  38.                         'title' => $this->trans('Ticket Id'),
  39.                         'info' => $this->trans('ticket.id.placeHolders.info'),
  40.                     ],
  41.                     'subject' => [
  42.                         'title' => $this->trans('Ticket Subject'),
  43.                         'info' => $this->trans('ticket.subject.placeHolders.info'),
  44.                     ],
  45.                     'message' => [
  46.                         'title' => $this->trans('Ticket Message'),
  47.                         'info' => $this->trans('ticket.message.placeHolders.info'),
  48.                     ],
  49.                     'attachments' => [
  50.                         'title' => $this->trans('Ticket Attachments'),
  51.                         'info' => $this->trans('ticket.attachments.placeHolders.info'),
  52.                     ],
  53.                     'threadMessage' => [
  54.                         'title' => $this->trans('Ticket Thread Message'),
  55.                         'info' => $this->trans('ticket.threadMessage.placeHolders.info'),
  56.                     ],
  57.                     'tags' => [
  58.                         'title' => $this->trans('Ticket Tags'),
  59.                         'info' => $this->trans('ticket.tags.placeHolders.info'),
  60.                     ],
  61.                     'source' => [
  62.                         'title' => $this->trans('Ticket Source'),
  63.                         'info' => $this->trans('ticket.source.placeHolders.info'),
  64.                     ],
  65.                     'status' => [
  66.                         'title' => $this->trans('Ticket Status'),
  67.                         'info' => $this->trans('ticket.status.placeHolders.info'),
  68.                     ],
  69.                     'priority' => [
  70.                         'title' => $this->trans('Ticket Priority'),
  71.                         'info' => $this->trans('ticket.priority.placeHolders.info'),
  72.                     ],
  73.                     'group' => [
  74.                         'title' => $this->trans('Ticket Group'),
  75.                         'info' => $this->trans('ticket.group.placeHolders.info'),
  76.                     ],
  77.                     'team' => [
  78.                         'title' => $this->trans('Ticket Team'),
  79.                         'info' => $this->trans('ticket.team.placeHolders.info'),
  80.                     ],
  81.                     'customerName' => [
  82.                         'title' => $this->trans('Ticket Customer Name'),
  83.                         'info' => $this->trans('ticket.customerName.placeHolders.info'),
  84.                     ],
  85.                     'customerEmail' => [
  86.                         'title' => $this->trans('Ticket Customer Email'),
  87.                         'info' => $this->trans('ticket.customerEmail.placeHolders.info'),
  88.                     ],
  89.                     'agentName' => [
  90.                         'title' => $this->trans('Ticket Agent Name'),
  91.                         'info' => $this->trans('ticket.agentName.placeHolders.info'),
  92.                     ],
  93.                     'agentEmail' => [
  94.                         'title' => $this->trans('Ticket Agent Email'),
  95.                         'info' => $this->trans('ticket.agentEmail.placeHolders.info'),
  96.                     ],
  97.                     'agentLink' => [
  98.                         'title' => $this->trans('Ticket Agent Link'),
  99.                         'info' => $this->trans('ticket.link.placeHolders.info'),
  100.                     ],
  101.                     'customerLink' => [
  102.                         'title' => $this->trans('Ticket Customer Link'),
  103.                         'info' => $this->trans('ticket.link.placeHolders.info'),
  104.                     ],
  105.                     'collaboratorName' => [
  106.                         'title' => $this->trans('Last Collaborator Name'),
  107.                         'info' => $this->trans('ticket.collaborator.name.placeHolders.info'),
  108.                     ],
  109.                     'collaboratorEmail' => [
  110.                         'title' => $this->trans('Last Collaborator Email'),
  111.                         'info' => $this->trans('ticket.collaborator.email.placeHolders.info'),
  112.                     ],
  113.                 ],
  114.                 'user'  => [
  115.                     'userName' => [
  116.                         'title' => $this->trans('Agent/ Customer Name'),
  117.                         'info' => $this->trans('user.name.info'),
  118.                     ],
  119.                     'userEmail' => [
  120.                         'title' => $this->trans('Email'),
  121.                         'info' => $this->trans('user.email.info'),
  122.                     ],
  123.                     'accountValidationLink' => [
  124.                         'title' => $this->trans('Account Validation Link'),
  125.                         'info' => $this->trans('user.account.validate.link.info'),
  126.                     ],
  127.                     'forgotPasswordLink' => [
  128.                         'title' => $this->trans('Password Forgot Link'),
  129.                         'info' => $this->trans('user.password.forgot.link.info'),
  130.                     ],
  131.                 ],
  132.                 'global' => [
  133.                     'companyName' => [
  134.                         'title' => $this->trans('Company Name'),
  135.                         'info' => $this->trans('global.companyName'),
  136.                     ],
  137.                     'companyLogo' => [
  138.                         'title' => $this->trans('Company Logo'),
  139.                         'info' => $this->trans('global.companyLogo'),
  140.                     ],
  141.                     'companyUrl' => [
  142.                         'title' => $this->trans('Company URL'),
  143.                         'info' => $this->trans('global.companyUrl'),
  144.                     ],
  145.                 ],
  146.             ];
  147.         } elseif ($template == 'savedReply') {
  148.             $placeHolders = [
  149.                 'ticket' => [
  150.                     'id' => [
  151.                         'title' => $this->trans('Ticket Id'),
  152.                         'info' => $this->trans('ticket.id.placeHolders.info'),
  153.                     ],
  154.                     'subject' => [
  155.                         'title' => $this->trans('Ticket Subject'),
  156.                         'info' => $this->trans('ticket.subject.placeHolders.info'),
  157.                     ],
  158.                     'status' => [
  159.                         'title' => $this->trans('Ticket Status'),
  160.                         'info' => $this->trans('ticket.status.placeHolders.info'),
  161.                     ],
  162.                     'priority' => [
  163.                         'title' => $this->trans('Ticket Priority'),
  164.                         'info' => $this->trans('ticket.priority.placeHolders.info'),
  165.                     ],
  166.                     'group' => [
  167.                         'title' => $this->trans('Ticket Group'),
  168.                         'info' => $this->trans('ticket.group.placeHolders.info'),
  169.                     ],
  170.                     'team' => [
  171.                         'title' => $this->trans('Ticket Team'),
  172.                         'info' => $this->trans('ticket.team.placeHolders.info'),
  173.                     ],
  174.                     'customerName' => [
  175.                         'title' => $this->trans('Ticket Customer Name'),
  176.                         'info' => $this->trans('ticket.customerName.placeHolders.info'),
  177.                     ],
  178.                     'customerEmail' => [
  179.                         'title' => $this->trans('Ticket Customer Email'),
  180.                         'info' => $this->trans('ticket.customerEmail.placeHolders.info'),
  181.                     ],
  182.                     'agentName' => [
  183.                         'title' => $this->trans('Ticket Agent Name'),
  184.                         'info' => $this->trans('ticket.agentName.placeHolders.info'),
  185.                     ],
  186.                     'agentEmail' => [
  187.                         'title' => $this->trans('Ticket Agent Email'),
  188.                         'info' => $this->trans('ticket.agentEmail.placeHolders.info'),
  189.                     ],
  190.                     'link' => [
  191.                         'title' => $this->trans('Ticket Link'),
  192.                         'info' => $this->trans('ticket.link.placeHolders.info'),
  193.                     ],
  194.                 ],
  195.             ];
  196.         } elseif ($template == 'ticketNote') {
  197.             $placeHolders = [
  198.                 'type' => [
  199.                     'previousType' => [
  200.                         'title' => $this->trans('Previous Type'),
  201.                         'info' => $this->trans('type.previous.placeHolders.info'),
  202.                     ],
  203.                     'updatedType' => [
  204.                         'title' => $this->trans('Updated Type'),
  205.                         'info' => $this->trans('type.updated.placeHolders.info'),
  206.                     ],
  207.                 ],
  208.                 'status' => [
  209.                     'previousStatus' => [
  210.                         'title' => $this->trans('Previous Status'),
  211.                         'info' => $this->trans('status.previous.placeHolders.info'),
  212.                     ],
  213.                     'updatedStatus' => [
  214.                         'title' => $this->trans('Updated Status'),
  215.                         'info' => $this->trans('status.updated.placeHolders.info'),
  216.                     ],
  217.                 ],
  218.                 'group' => [
  219.                     'previousGroup' => [
  220.                         'title' => $this->trans('Previous Group'),
  221.                         'info' => $this->trans('group.previous.placeHolders.info'),
  222.                     ],
  223.                     'updatedGroup' => [
  224.                         'title' => $this->trans('Updated Group'),
  225.                         'info' => $this->trans('group.updated.placeHolders.info'),
  226.                     ],
  227.                 ],
  228.                 'team' => [
  229.                     'previousTeam' => [
  230.                         'title' => $this->trans('Previous Team'),
  231.                         'info' => $this->trans('team.previous.placeHolders.info'),
  232.                     ],
  233.                     'updatedTeam' => [
  234.                         'title' => $this->trans('Updated Team'),
  235.                         'info' => $this->trans('team.updated.placeHolders.info'),
  236.                     ],
  237.                 ],
  238.                 'priority' => [
  239.                     'previousPriority' => [
  240.                         'title' => $this->trans('Previous Priority'),
  241.                         'info' => $this->trans('priority.previous.placeHolders.info'),
  242.                     ],
  243.                     'updatedPriority' => [
  244.                         'title' => $this->trans('Updated Priority'),
  245.                         'info' => $this->trans('priority.updated.placeHolders.info'),
  246.                     ],
  247.                 ],
  248.                 'agent' => [
  249.                     'previousAgent' => [
  250.                         'title' => $this->trans('Previous Agent'),
  251.                         'info' => $this->trans('agent.previous.placeHolders.info'),
  252.                     ],
  253.                     'updatedAgent' => [
  254.                         'title' => $this->trans('Updated Agent'),
  255.                         'info' => $this->trans('agent.updated.placeHolders.info'),
  256.                     ],
  257.                     'responsePerformingAgent' => [
  258.                         'title' => $this->trans('Response Performing Agent'),
  259.                         'info' => $this->trans('agent.response.placeHolders.info'),
  260.                     ],
  261.                 ],
  262.             ];
  263.         } elseif($template == 'manualNote') {
  264.             $placeHolders = [
  265.                 'ticket' => [
  266.                     'id' => [
  267.                         'title' => $this->trans('Ticket Id'),
  268.                         'info' => $this->trans('ticket.id.placeHolders.info'),
  269.                     ],
  270.                     'subject' => [
  271.                         'title' => $this->trans('Ticket Subject'),
  272.                         'info' => $this->trans('ticket.subject.placeHolders.info'),
  273.                     ],
  274.                     'status' => [
  275.                         'title' => $this->trans('Ticket Status'),
  276.                         'info' => $this->trans('ticket.status.placeHolders.info'),
  277.                     ],
  278.                     'priority' => [
  279.                         'title' => $this->trans('Ticket Priority'),
  280.                         'info' => $this->trans('ticket.priority.placeHolders.info'),
  281.                     ],
  282.                     'group' => [
  283.                         'title' => $this->trans('Ticket Group'),
  284.                         'info' => $this->trans('ticket.group.placeHolders.info'),
  285.                     ],
  286.                     'team' => [
  287.                         'title' => $this->trans('Ticket Team'),
  288.                         'info' => $this->trans('ticket.team.placeHolders.info'),
  289.                     ],
  290.                     'customerName' => [
  291.                         'title' => $this->trans('Ticket Customer Name'),
  292.                         'info' => $this->trans('ticket.customerName.placeHolders.info'),
  293.                     ],
  294.                     'customerEmail' => [
  295.                         'title' => $this->trans('Ticket Customer Email'),
  296.                         'info' => $this->trans('ticket.customerEmail.placeHolders.info'),
  297.                     ],
  298.                     'agentName' => [
  299.                         'title' => $this->trans('Ticket Agent Name'),
  300.                         'info' => $this->trans('ticket.agentName.placeHolders.info'),
  301.                     ],
  302.                     'agentEmail' => [
  303.                         'title' => $this->trans('Ticket Agent Email'),
  304.                         'info' => $this->trans('ticket.agentEmail.placeHolders.info'),
  305.                     ],
  306.                 ],
  307.             ];
  308.         }
  309.         return $placeHolders;
  310.     }
  311.     public function getEmailPlaceholderValues(User $user$userType 'member')
  312.     {
  313.         if (null == $user->getVerificationCode()) {
  314.             // Set user verification code
  315.             $user->setVerificationCode(TokenGenerator::generateToken());
  316.             $this->entityManager->persist($user);
  317.             $this->entityManager->flush();
  318.         }
  319.         $router $this->container->get('router');
  320.         $helpdeskWebsite $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneByCode('helpdesk');
  321.         // Link to company knowledgebase
  322.         if (false == array_key_exists('UVDeskSupportCenterBundle'$this->container->getParameter('kernel.bundles'))) {
  323.             $companyURL $this->container->getParameter('uvdesk.site_url');
  324.         } else {
  325.             $companyURL $router->generate('helpdesk_knowledgebase', [], UrlGeneratorInterface::ABSOLUTE_URL);
  326.         }
  327.         // Resolve path to helpdesk brand image
  328.         $companyLogoURL sprintf('http://%s%s'$this->container->getParameter('uvdesk.site_url'), '/bundles/uvdeskcoreframework/images/uv-avatar-uvdesk.png');
  329.         $helpdeskKnowledgebaseWebsite $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneByCode('knowledgebase');
  330.         if (!empty($helpdeskKnowledgebaseWebsite) && null != $helpdeskKnowledgebaseWebsite->getLogo()) {
  331.             $companyLogoURL sprintf('http://%s%s'$this->container->getParameter('uvdesk.site_url'), $helpdeskKnowledgebaseWebsite->getLogo());
  332.         }
  333.         
  334.         // Link to update account login credentials
  335.         $updateCredentialsURL $router->generate'helpdesk_update_account_credentials', [
  336.             'email' => $user->getEmail(),
  337.             'verificationCode' => $user->getVerificationCode(),
  338.         ], UrlGeneratorInterface::ABSOLUTE_URL);
  339.         $placeholderParams = [
  340.             'user.userName' => $user->getFullName(),
  341.             'user.userEmail' => $user->getEmail(),
  342.             'user.assignUserEmail' => $user->getEmail(),
  343.             'user.forgotPasswordLink' => "<a href='$updateCredentialsURL'>$updateCredentialsURL</a>",
  344.             'user.accountValidationLink' => "<a href='$updateCredentialsURL'>$updateCredentialsURL</a>",
  345.             'global.companyName' => $helpdeskWebsite->getName(),
  346.             'global.companyLogo' => "<img style='max-height:60px' src='$companyLogoURL'/>",
  347.             'global.companyUrl' => "<a href='$companyURL'>$companyURL</a>",
  348.         ];
  349.         
  350.         return $placeholderParams;
  351.     }
  352.     public function getTicketPlaceholderValues(Ticket $ticket$type "")
  353.     {
  354.         $supportTeam $ticket->getSupportTeam();
  355.         $supportGroup $ticket->getSupportGroup();
  356.         $supportTags array_map(function ($supportTag) { return $supportTag->getName(); }, $ticket->getSupportTags()->toArray());
  357.         
  358.         $router $this->container->get('router');
  359.         $helpdeskWebsite $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneByCode('helpdesk');
  360.         
  361.         // Resolve path to helpdesk brand image
  362.         $companyLogoURL sprintf('http://%s%s'$this->container->getParameter('uvdesk.site_url'), '/bundles/uvdeskcoreframework/images/uv-avatar-uvdesk.png');
  363.         $helpdeskKnowledgebaseWebsite $this->entityManager->getRepository('UVDeskCoreFrameworkBundle:Website')->findOneByCode('knowledgebase');
  364.         if (!empty($helpdeskKnowledgebaseWebsite) && null != $helpdeskKnowledgebaseWebsite->getLogo()) {
  365.             $companyLogoURL sprintf('http://%s%s'$this->container->getParameter('uvdesk.site_url'), $helpdeskKnowledgebaseWebsite->getLogo());
  366.         }
  367.         
  368.         // Link to company knowledgebase
  369.         if (false == array_key_exists('UVDeskSupportCenterBundle'$this->container->getParameter('kernel.bundles'))) {
  370.             $companyURL $this->container->getParameter('uvdesk.site_url');
  371.         } else {
  372.             $companyURL $router->generate('helpdesk_knowledgebase', [], UrlGeneratorInterface::ABSOLUTE_URL);
  373.         }
  374.         $customerPartialDetails $ticket->getCustomer()->getCustomerInstance()->getPartialDetails();
  375.         $agentPartialDetails $ticket->getAgent() ? $ticket->getAgent()->getAgentInstance()->getPartialDetails() : null;
  376.         //Ticket Url and create ticket url for agent
  377.         $viewTicketURLAgent $router->generate('helpdesk_member_ticket', [
  378.             'ticketId' => $ticket->getId(),
  379.         ], UrlGeneratorInterface::ABSOLUTE_URL);
  380.         $generateTicketURLAgent $router->generate('helpdesk_member_create_ticket', [], UrlGeneratorInterface::ABSOLUTE_URL);
  381.         if (false != array_key_exists('UVDeskSupportCenterBundle'$this->container->getParameter('kernel.bundles'))) {
  382.                 $viewTicketURL $router->generate('helpdesk_customer_ticket', [
  383.                     'id' => $ticket->getId(),
  384.                 ], UrlGeneratorInterface::ABSOLUTE_URL);
  385.     
  386.                 $generateTicketURLCustomer $router->generate('helpdesk_customer_create_ticket', [], UrlGeneratorInterface::ABSOLUTE_URL);
  387.         } else {
  388.             $viewTicketURL '';
  389.             $generateTicketURLCustomer '';
  390.         }
  391.         $placeholderParams = [
  392.             'ticket.id' => $ticket->getId(),
  393.             'ticket.subject' => $ticket->getSubject(),
  394.             'ticket.message' => count($ticket->getThreads()) > preg_replace("/<img[^>]+\>/i"""$ticket->getThreads()->get(0)->getMessage()) : '',
  395.             'ticket.threadMessage' => $this->threadMessage($ticket),
  396.             'ticket.tags' => implode(','$supportTags),
  397.             'ticket.source' => ucfirst($ticket->getSource()),
  398.             'ticket.status' => $ticket->getStatus()->getDescription(),
  399.             'ticket.priority' => $ticket->getPriority()->getDescription(),
  400.             'ticket.team' => $supportTeam $supportTeam->getName() : '',
  401.             'ticket.group' => $supportGroup $supportGroup->getName() : '',
  402.             'ticket.customerName' => $customerPartialDetails['name'],
  403.             'ticket.customerEmail' => $customerPartialDetails['email'],
  404.             'ticket.agentName' => !empty($agentPartialDetails) ? $agentPartialDetails['name'] : '',
  405.             'ticket.agentEmail' => !empty($agentPartialDetails) ? $agentPartialDetails['email'] : '',
  406.             'ticket.attachments' => '',
  407.             'ticket.collaboratorName' => $this->getCollaboratorName($ticket),
  408.             'ticket.collaboratorEmail' => $this->getCollaboratorEmail($ticket),
  409.             'ticket.agentLink' => sprintf("<a href='%s'>#%s</a>"$viewTicketURLAgent$ticket->getId()),
  410.             'ticket.ticketGenerateUrlAgent' => sprintf("<a href='%s'>click here</a>"$generateTicketURLAgent),
  411.             'ticket.customerLink' => sprintf("<a href='%s'>#%s</a>"$viewTicketURL$ticket->getId()),
  412.             'ticket.ticketGenerateUrlCustomer' => sprintf("<a href='%s'>click here</a>"$generateTicketURLCustomer),
  413.             'global.companyName' => $helpdeskWebsite->getName(),
  414.             'global.companyLogo' => "<img style='max-height:60px' src='$companyLogoURL'/>",
  415.             'global.companyUrl' => "<a href='$companyURL'>$companyURL</a>",
  416.         ];
  417.         return $placeholderParams;
  418.     }
  419.     public function threadMessage($ticket)
  420.     {
  421.         $message null;
  422.         if (isset($ticket->createdThread) && $ticket->createdThread->getThreadType() != "note") {
  423.             return preg_replace("/<img[^>]+\>/i"""$ticket->createdThread->getMessage());
  424.         } elseif (isset($ticket->currentThread) && $ticket->currentThread->getThreadType() != "note") {
  425.             return  preg_replace("/<img[^>]+\>/i"""$ticket->currentThread->getMessage());
  426.         } else {
  427.             $messages $ticket->getThreads();
  428.             for ($i count($messages) - $i >= 0  $i--) { 
  429.                 if (isset($messages[$i]) && $messages[$i]->getThreadType() != "note") {
  430.                     return preg_replace("/<img[^>]+\>/i"""$messages[$i]->getMessage());
  431.                 }
  432.             }
  433.         }
  434.         return "";
  435.     }
  436.     public function processEmailSubject($subject, array $emailPlaceholders = [])
  437.     {
  438.         foreach ($emailPlaceholders as $var => $value) {
  439.             $subject strtr($subject, ["{%$var%}" => $value"{% $var %}" => $value]);
  440.         }
  441.         
  442.         return $subject;
  443.     }
  444.     public function processEmailContent($content, array $emailPlaceholders = [], $isSavedReply false)
  445.     {
  446.         $twigTemplatingEngine $this->container->get('twig');
  447.         $baseEmailTemplate $this->container->getParameter('uvdesk.default.templates.email');
  448.         foreach ($emailPlaceholders as $var => $value) {
  449.             $content strtr($content, ["{%$var%}" => $value"{% $var %}" => $value]);
  450.         }
  451.         $content $isSavedReply stripslashes($content) : htmlspecialchars_decode(preg_replace(['#&lt;script&gt;#''#&lt;/script&gt;#'], ['&amp;lt;script&amp;gt;''&amp;lt;/script&amp;gt;'], $content));
  452.         return $twigTemplatingEngine->render($baseEmailTemplate, ['message' => $content]);
  453.     }
  454.     public function sendMail($subject$content$recipient, array $headers = [], $mailboxEmail null, array $attachments = [], $cc = [], $bcc = [])
  455.     {
  456.         $error_check false;
  457.         if (empty($mailboxEmail)) {
  458.             // Send email on behalf of support helpdesk
  459.             $supportEmail $this->container->getParameter('uvdesk.support_email.id');
  460.             $supportEmailName $this->container->getParameter('uvdesk.support_email.name');
  461.             $mailerID $this->container->getParameter('uvdesk.support_email.mailer_id');
  462.         } else {
  463.             // Register automations conditionally if AutomationBundle has been added as an dependency.
  464.             if (!array_key_exists('UVDeskMailboxBundle'$this->container->getParameter('kernel.bundles'))) {
  465.                 return;
  466.             } else {
  467.                 // Send email on behalf of configured mailbox
  468.                 try {
  469.                     $mailbox $this->container->get('uvdesk.mailbox')->getMailboxByEmail($mailboxEmail);
  470.     
  471.                     if (true === $mailbox['enabled']) {
  472.                         $supportEmail $mailbox['email'];
  473.                         $supportEmailName $mailbox['name'];
  474.                         $mailerID $mailbox['smtp_server']['mailer_id'];
  475.                     } else {
  476.                         // @TODO: Log mailbox disabled notice
  477.                         return;
  478.                     }
  479.                 } catch (\Exception $e) {
  480.                     $error_check true;
  481.                     // @TODO: Log exception - Mailbox not found
  482.                     return;
  483.                 }
  484.             }
  485.         }
  486.         // Retrieve mailer to be used for sending emails
  487.         try {
  488.             $mailer $this->container->get('swiftmailer.mailer' . (('default' == $mailerID) ? '' ".$mailerID"));
  489.             $mailer->getTransport()->setPassword(base64_decode($mailer->getTransport()->getPassword()));
  490.         } catch (\Exception $e) {
  491.             $error_check true;
  492.             // @TODO: Log exception - Mailer not found
  493.             return;
  494.         }
  495.         // Create a message
  496.         $message = (new \Swift_Message($subject))
  497.             ->setFrom([$supportEmail => $supportEmailName])
  498.             ->setTo($recipient)
  499.             ->setBcc($bcc)
  500.             ->setCc($cc)
  501.             ->setBody($content'text/html')
  502.             ->addPart(strip_tags($content), 'text/plain');
  503.         foreach ($attachments as $attachment) {
  504.             if (!empty($attachment['path']) && !empty($attachment['name'])) {
  505.                 $message->attach(\Swift_Attachment::fromPath($attachment['path'])->setFilename($attachment['name']));
  506.                 
  507.                 continue;
  508.             } 
  509.             $message->attach(\Swift_Attachment::fromPath($attachment));
  510.         }
  511.         $messageHeaders $message->getHeaders();
  512.         foreach ($headers as $headerName => $headerValue) {
  513.             if(is_array($headerValue)) {
  514.                 $headerValue $headerValue['messageId'];
  515.             }
  516.             $messageHeaders->addTextHeader($headerName$headerValue);
  517.         }
  518.         try {
  519.             $messageId $message->getId();
  520.             $mailer->send($message);
  521.             
  522.             return "<$messageId>";
  523.         } catch (\Exception $e) {
  524.             $error_check true;
  525.             // @TODO: Log exception
  526.         }
  527.         if ($error_check == true) {
  528.             $this->session->getFlashBag()->add('warning'$this->container->get('translator')->trans('Warning ! Swiftmailer not working. An error has occurred while sending emails!'));   
  529.         }
  530.         return null;
  531.     }
  532.     public function getCollaboratorName($ticket)
  533.     {
  534.         $ticket->lastCollaborator null;
  535.         $name null;
  536.         if($ticket->getCollaborators() != null && count($ticket->getCollaborators()) > 0) {
  537.             try {
  538.                 $ticket->lastCollaborator $ticket->getCollaborators()[ -count($ticket->getCollaborators()) ];
  539.             } catch(\Exception $e) {
  540.             }
  541.         }
  542.         if($ticket->lastCollaborator != null) {
  543.             $name =  $ticket->lastCollaborator->getFirstName()." ".$ticket->lastCollaborator->getLastName();
  544.         }
  545.         
  546.         return $name != null $name '';
  547.         
  548.     }
  549.     public function getCollaboratorEmail($ticket)
  550.     {
  551.         $ticket->lastCollaborator null;
  552.         $email null;
  553.         if($ticket->getCollaborators() != null && count($ticket->getCollaborators()) > 0) {
  554.             try {
  555.                 $ticket->lastCollaborator $ticket->getCollaborators()[ -count($ticket->getCollaborators()) ];
  556.             } catch(\Exception $e) {
  557.             }
  558.         }
  559.         if($ticket->lastCollaborator != null) {
  560.             $email $ticket->lastCollaborator->getEmail();
  561.         }
  562.         
  563.         return $email != null $email '';;
  564.     }
  565. }