vendor/kunstmaan/form-bundle/Helper/FormMailer.php line 32

Open in your IDE?
  1. <?php
  2. namespace Kunstmaan\FormBundle\Helper;
  3. use Kunstmaan\FormBundle\Entity\FormSubmission;
  4. use Swift_Mailer;
  5. use Swift_Message;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use Symfony\Component\Templating\EngineInterface;
  9. use Twig\Environment;
  10. /**
  11.  * The form mailer
  12.  */
  13. class FormMailer implements FormMailerInterface
  14. {
  15.     /** @var \Swift_Mailer */
  16.     private $mailer;
  17.     /** @var EngineInterface|Environment */
  18.     private $twig;
  19.     /** @var RequestStack */
  20.     private $requestStack;
  21.     /**
  22.      * @param Swift_Mailer                    $mailer
  23.      * @param EngineInterface                 $twig
  24.      * @param ContainerInterface|RequestStack $requestStack
  25.      */
  26.     public function __construct(Swift_Mailer $mailer/*Environment*/ $twig/*RequestStack*/ $requestStack)
  27.     {
  28.         $this->mailer $mailer;
  29.         $this->twig $twig;
  30.         if ($twig instanceof EngineInterface) {
  31.             @trigger_error('Passing the "@templating" service as the 2nd argument is deprecated since KunstmaanFormBundle 5.4 and will be replaced by the Twig service in KunstmaanFormBundle 6.0. Injected the "@twig" service instead.'E_USER_DEPRECATED);
  32.         }
  33.         $this->requestStack $requestStack;
  34.         if ($requestStack instanceof ContainerInterface) {
  35.             @trigger_error('Passing the container as the 3th argument is deprecated since KunstmaanFormBundle 5.4 and will be replaced by the "request_stack" service in KunstmaanFormBundle 6.0. Injected the "@request_stack" service instead.'E_USER_DEPRECATED);
  36.             $this->requestStack $requestStack->get('request_stack');
  37.         }
  38.     }
  39.     /**
  40.      * @param FormSubmission $submission The submission
  41.      * @param string         $from       The from address
  42.      * @param string         $to         The to address(es) seperated by \n
  43.      * @param string         $subject    The subject
  44.      */
  45.     public function sendContactMail(FormSubmission $submission$from$to$subject)
  46.     {
  47.         $request $this->requestStack->getCurrentRequest();
  48.         $toArr explode("\r\n"$to);
  49.         $message = (new Swift_Message($subject))
  50.             ->setFrom($from)
  51.             ->setTo($toArr)
  52.             ->setBody(
  53.                 $this->twig->render(
  54.                     '@KunstmaanForm/Mailer/mail.html.twig',
  55.                     [
  56.                         'submission' => $submission,
  57.                         'host' => $request->getScheme().'://'.$request->getHttpHost(),
  58.                     ]
  59.                 ),
  60.                 'text/html'
  61.             );
  62.         $this->mailer->send($message);
  63.     }
  64. }