在Symfony 4中使用Swift Mailer发送邮件

时间:2019-03-14 07:03:10

标签: php symfony4 swiftmailer

我正在尝试使用symfony 4通过快速邮件发送电子邮件。但是电子邮件没有发送。

.env

MAILER_URL=smtp://localhost:25?encryption=&auth_mode=

控制器

/**
     * @Route("/registration", name="new_registration")
     * Method({"GET","POST"})
     */

    public function newRegistration(Request $request, \Swift_Mailer $mailer)
    {

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

            $message = (new \Swift_Message('Hello Mail'))
                ->setFrom('noreply@cccc.org')
                ->setTo('abcccc@gmail.com')
                ->setBody(
                    $this->renderView(
                        'main/registrationEmail.html.twig',
                        ['name' => $name]
                    ),
                    'text/html'
                );
            try {
                $mailer->send($message);
            } catch (\Swift_TransportException $exception) {
                echo $exception->getMessage();
            } catch (\Exception $exception) {
                echo $exception->getMessage();
            }

            return $this->render('main/registrationSuccess.html.twig');
        }
        return $this->render('main/registration.html.twig');
    }

没有显示任何错误。但是邮件没有发送。请帮助我。

更新

我尝试通过控制台并使用php bin/console swiftmailer:email:send发送。由此我得到了下面的错误。

2019-03-14T11:40:32+01:00 [error] Exception occurred while flushing email queue: Connection could not be established with host localhost [No connection could be made because the target machine actively refused it.
 #10061]

0 个答案:

没有答案
相关问题