I am trying to sent emails via swift mail using symfony 4. Code below is I tried so far. But email is not sending.
.env
MAILER_URL=smtp://localhost:25?encryption=&auth_mode=
controller
/**
* @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');
}
There is not showing any error. But mail is not sending. Please help me on this.
UPDATE
I tried to send by console and using php bin/console swiftmailer:email:send
. From that I got below error.
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]