Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // .env
- MAILER_URL=gmail://chilum7007:?????@localhost
- private $mailer;
- private $transport;
- public function __construct(\Swift_Mailer $mailer, \Swift_Transport $transport)
- {
- $this->mailer = $mailer;
- $this->transport = $transport;
- }
- public function sendMessageFromTo($from, $to,$message )
- {
- $transport = (new Swift_SmtpTransport('smtp.gmail.com', 465))
- ->setUsername('chilum7007')
- ->setPassword('toto007')
- ->setEncryption('tls');
- try {
- $mess = (new \Swift_Message($message))
- ->setFrom($from, "sensiolab")
- ->setTo($to)
- ->setBody(
- $this->renderView(
- // templates/emails/registration.html.twig
- 'emails/registration.html.twig',
- []
- ),
- 'text/html'
- );
- $this->mailer->send($mess);
- $this->addFlash('success', "Votre email a ete envoyé");
- }
- catch( \Exception $e)
- {
- $this->addFlash('error', "Error");
- }
- }
- /**
- * @Route("/sendemail")
- *
- */
- public function sendingEmail()
- {
- $this->sendMessageFromTo('chilum7007@gmail.com','serguei.khan@gmail.com', "Votre commande est passée");
- return $this->render("purchase/sendemail-test.html.twig");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement