src/Controller/ContactController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  5. use Symfony\Component\Mailer\MailerInterface;
  6. use Symfony\Component\Mime\Email;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class ContactController extends BaseController
  9. {
  10.     /**
  11.      * Ruta de contacto
  12.      * @Route("/contacto", name="contact")
  13.      * 
  14.      * @return Response
  15.      */
  16.     public function show(): Response
  17.     {
  18.         return $this->render(
  19.             'pages/contact.html.twig'
  20.             [
  21.                 'title' => 'Colombia Criptomonedas | Contacto',
  22.                 'data' => $this->datos
  23.             ]
  24.         );
  25.     }
  26.     /**
  27.      * Ruta para envio de correos
  28.      * @Route("/correo", name="mailer")
  29.      */
  30.     public function mail(MailerInterface $mailer)
  31.     {
  32.         $email = (new Email())
  33.             ->from('contacto@colombiacriptomoneda.com')
  34.             ->to('davidmarsant@gmail.com')
  35.             ->subject('Correo de Prueba')
  36.             ->text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus aliquet id felis.');
  37.         $msj '';
  38.         try {
  39.             $mailer->send$email );
  40.         } catch (TransportExceptionInterface $e) {
  41.             $msj $e->getMessage();
  42.         }
  43.         return $this->render(
  44.             'pages/contact.html.twig'
  45.             [
  46.                 'title' => 'Colombia Criptomonedas | Contacto',
  47.                 'data' => $this->datos,
  48.                 'message' => $msj
  49.             ]
  50.         );
  51.     }
  52. }
  53. ?>