简体   繁体   中英

How to set multiple mails in symfony 4 using swiftmailer-bundle

I'm using swiftmailer-bundle for sending emails from my applications

I have added this in env.

MAILER_URL=gmail://mailExample@mail.com:mypassword@localhost?encryption=tls&auth_mode=oauth

And this when i need to sent the email from controller

$message = (new \Swift_Message($objet))
                ->setFrom('mailExample@mail.com','example')
                ->setTo(exemple2@mail.com)
                ->setBody("test")
                )

My question is how to add another mail?, i need to use more than one mail

Can i add two lines of MAILER_URL in env. ??

Check out the official documentation on using multiple mailers.

https://symfony.com/doc/current/reference/configuration/swiftmailer.html#using-multiple-mailers

swiftmailer:
    default_mailer: first_mailer
    mailers:
        first_mailer:
            url: '%env(MAILER_URL)%'
        second_mailer:
            url: '%env(SECOND_MAILER_URL)%'
// returns the first mailer
$container->get('swiftmailer.mailer.first_mailer');

// returns the second mailer
$container->get('swiftmailer.mailer.second_mailer');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM