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

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