SwiftMailer

Default
,

Bonjour,

J'ai un problème que j'imagine assez bete mais comment m'y prendre, je ne sais pas trop.

Mon but est d'envoyer un email lorsqu'un utilisateur s'enregistre sur le site.

J'ai donc une entité subscriber

<?php

namespace App\Controller\Front\Customer;

use App\Controller\Modules\Mailer\MailerController;
use App\Entity\Customer\Users;
use App\Form\UsersType;
use App\Repository\Customer\UsersRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;

class SubscriberController extends AbstractController
{
     /**
     * @var UsersRepository
     */
    private $repository;

    /**
     * @var ObjectManager
     */
    private $em;

    public function __construct(UsersRepository $repository, ObjectManager $em)
    {
        $this->repository = $repository;
        $this->em = $em;
    }

    /**
     * @Route("/inscription", name="subscriber")
     */
    public function index(Request $request, UserPasswordEncoderInterface $passwordEncoder)
    {
        $users = new Users();

        $form = $this->createForm(UsersType::class, $users);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {

            $password = $passwordEncoder->encodePassword($users, $users->getPassword());
            $users->setPassword($password);

            $this->em->persist($users);
            $this->em->flush();
            $this->addFlash('success', 'Enregistrement effectué avec succès');

            $name = $users->getUsername();
            $mail = $users->getEmail();

            MailerController::sendSubscribe($name, $mail, $mailer);

            return $this->redirectToRoute('login');
        }

        return $this->render('security/subscriber.html.twig', [
            'users ' => $users,
            'form' => $form->createView()
        ]);
    }
}

et une entité Mailer :

<?php

namespace App\Controller\Modules\Mailer;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\Common\Persistence\ObjectManager;

class MailerController extends AbstractController
{

    public function sendSubscribe($name, $email, \Swift_Mailer $mailer)
    {
        $message = (new \Swift_Message('Hello Email'))
            ->setFrom($email)
            ->setTo('recipient@example.com')
            ->setBody(
                $this->renderView(
                    'emails/subscriber/subscriber.html.twig',
                    ['name' => $name]
                ),
                'text/html'
            )

            // you can remove the following code if you don't define a text version for your emails
            ->addPart(
                $this->renderView(
                    // templates/emails/registration.txt.twig
                    'emails/subscriber/subscriber.txt.twig',
                    ['name' => $name]
                ),
                'text/plain'
            )
        ;

        $mailer->send($message);
    }
}

Forcement j'ai une erreur qui m'indique que pour ma fonction sendSubscribe() il me manque un parametre, mais je ne sais pas quoi mettre à vrai dire.

Quelqu'un serait m'expliquer cela ?

Cordialement.