Answer the question
In order to leave comments, you need to log in
How to make a service for sending mail using Swiftmailer?
I want to make sending mail to a separate service
created a class
namespace AppBundle\Utils;
class SendOrder
{
protected $twig;
protected $mailer;
public function __construct(\Twig_Environment $twig, \Swift_Mailer $mailer)
{
$this->twig = $twig;
$this->mailer = $mailer;
}
public function sendOrderAction($book)
{
$body = $this->twig->render('AppBundle:Email:send_order.html.twig', array('name' => $book));
$message = \Swift_Message::newInstance()
->setSubject('Hello Email')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody($body);
$this->mailer->send($message);
}
}
#services,yml
app.sendorder:
class: AppBundle\Utils\SendOrder
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question