Completed
Pull Request — 5.0 (#2072)
by Jeroen
33:11
created

src/Kunstmaan/FormBundle/Helper/FormMailer.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FormBundle\Helper;
4
5
use Kunstmaan\FormBundle\Entity\FormSubmission;
6
use Swift_Mailer;
7
use Swift_Message;
8
use Swift_Mime_Message;
9
use Symfony\Bundle\TwigBundle\TwigEngine;
10
use Symfony\Component\DependencyInjection\ContainerInterface;
11
12
/**
13
 * The form mailer
14
 */
15
class FormMailer implements FormMailerInterface
16
{
17
    /** @var \Swift_Mailer */
18
    private $mailer;
19
20
    /** @var \Symfony\Bundle\TwigBundle\TwigEngine */
21
    private $templating;
22
23
    /** @var \Symfony\Component\DependencyInjection\ContainerInterface */
24
    private $container;
25
26
    /**
27
     * @param Swift_Mailer       $mailer     The mailer service
28
     * @param TwigEngine         $templating The templating service
29
     * @param ContainerInterface $container  The container
30
     */
31
    public function __construct(Swift_Mailer $mailer, TwigEngine $templating, ContainerInterface $container)
32
    {
33
        $this->mailer     = $mailer;
34
        $this->templating = $templating;
35
        $this->container  = $container;
36
    }
37
38
    /**
39
     * @param FormSubmission $submission The submission
40
     * @param string         $from       The from address
41
     * @param string         $to         The to address(es) seperated by \n
42
     * @param string         $subject    The subject
43
     */
44
    public function sendContactMail(FormSubmission $submission, $from, $to, $subject)
45
    {
46
        $request = $this->container->get('request_stack')->getCurrentRequest();
47
48
        $toArr = explode("\r\n", $to);
49
        /* @var $message Swift_Mime_Message */
50
        $message = Swift_Message::newInstance()->setSubject($subject)->setFrom($from)->setTo($toArr);
0 ignored issues
show
The method newInstance() does not seem to exist on object<Swift_Message>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        $message->setBody(
52
            $this->templating->render(
53
                'KunstmaanFormBundle:Mailer:mail.html.twig',
54
                array(
55
                    'submission' => $submission,
56
                    'host'       => $request->getScheme() . '://' . $request->getHttpHost()
57
                )
58
            ),
59
            'text/html'
60
        );
61
        $this->mailer->send($message);
62
    }
63
}
64