'Eventproblem Too few arguments to function

i have a problem with my Testproject, i tray to make Event, the function of this event is following, when the controller call the row with id 18 from the datebase, it will to call/dispach event, this event have to send email to a Email Adress. the problem, i cannot call this event from my eventlistener, because i get the wrong: Too few arguments to function App\customEvents\EmailEvent::SendEMail(), 0 passed in C:\xampp\htdocs\Authentication\src\EventListener\EmailListener.php on line 15 and exactly 1 expected

Controller:


    namespace App\Controller;
    use App\Entity\Posts;
    use App\Repository\PostsRepository;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\EventDispatcher\EventDispatcherInterface;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    
    class EventoController extends AbstractController
    {
        #[Route('/evento', name: 'app_evento')]
        public function index(PostsRepository $Posts, EventDispatcherInterface $eventDispatcher): Response
        {
              $todo=$Posts->find(18);
    
              $sendEmail=new \App\customEvents\EmailEvent;
              $eventDispatcher->dispatch($sendEmail, \App\customEvents\EmailEvent::NAME);
    
    
    
            return $this->render('evento/index.html.twig', [
                'getdaten' => $todo,
            ]);
        }
    }


EmailListener

    <?php
    namespace App\EventListener;
    use App\customEvents\EmailEvent;
    use Symfony\Component\Mailer\MailerInterface;
    
    class EmailListener
    {
        public function sendemailaktive( EmailEvent $MeinEmailEvent)
        {
          $MeinEmailEvent->SendEMail();
        }
    
    }


EmailEvent

    <?php
    namespace App\customEvents;
    use Symfony\Component\Mailer\MailerInterface;
    use Symfony\Component\Mime\Email;
    use Symfony\Bridge\Twig\Mime\TemplatedEmail;
    use Symfony\Component\EventDispatcher\EventDispatcher;
    use Symfony\Component\HttpFoundation\Request;
    
    class EmailEvent extends EventDispatcher
    {
        public const NAME = 'send.email';
    
        public function SendEMail(MailerInterface $mailer)
        {
          $email = (new Email())
          ->from('[email protected]')
          ->to('[email protected]')
          ->subject('Email From Send!')
          ->text('Sending emails is fun again!')
          ->html('<p>See Twig integration for better HTML integration!</p>');
          $mailer->send($email);
        }
    }





Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source