Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

446
Vistas
Use the symfony/mailer component without the symfony framework

I am working on a project that doesn't use any framework and I would like to use Symfony Mailer component to handle sending emails.

The installation part (composer require) was well handled and everything is included in my code without any error. However, I still have a problem : the documentation of the component seems to be written only for using it with the symfony framework. Indeed, it is refering to autoloaded config files that o bviously don't exist in my app.

This implementation seems to be very tricky and I was wondering if any of you guys already faced the same problem and what solution you came up with?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your question made me wonder too how it is easy to send mail only with the mailer component.

So I created a new project from scratch and tried the simplest possible version following the mailer component documentation.


use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;

class MyMailer
{
    // googleDns format is gmail+smtp://USERNAME:PASSWORD@default
    public function __construct(private string $googleDsn)
    {
    }

    public function send()
    {
        $template = file_get_contents('https://raw.githubusercontent.com/leemunroe/responsive-html-email-template/master/email.html');

        $transport = Transport::fromDsn($this->googleDsn);
        $mailer = new Mailer($transport);

        $email = (new Email())
            ->from('mygmail@address.com')
            ->to('thedelivery@gmail.com')
            ->subject('Time for Symfony Mailer!')
            ->html($template);

        $mailer->send($email);
    }
}

And I successfully received my mail. I send my mail with gmail, for your information. Transport class should do the sending job for you, but if not you can have a look to inside vendor/symfony/mailer/Transport folder

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda