【问题标题】:How to set multiple mails in symfony 4 using swiftmailer-bundle如何使用 swiftmailer-bundle 在 symfony 4 中设置多个邮件
【发布时间】:2019-04-15 23:13:48
【问题描述】:

我正在使用 swiftmailer-bundle 从我的应用程序发送电子邮件

我已经在环境中添加了这个。

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

当我需要从控制器发送电子邮件时

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

我的问题是如何添加另一封邮件?,我需要使用多个邮件

我可以在环境中添加两行 MAILER_URL。 ??

【问题讨论】:

  • 您的意思是发送到多个电子邮件地址吗?
  • @tim 我的意思是我想添加我的两封电子邮件,例如我想添加这两个邮件 ->setFrom('FirstMail@mail.com','example') 和 ->setFrom(' secondMail@mail.com','例子')
  • 我的意思是更多的来源不仅仅是一封邮件
  • 一封电子邮件中不能有 2 个地址

标签: php symfony swiftmailer


【解决方案1】:

查看有关使用多个邮件程序的官方文档。

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');

【讨论】:

  • 我看不懂文档,我将在其中添加邮件和密码
  • 我已经更新了我的答案,使其更加清晰。在您设置 MAILER_URL 环境变量的同一位置,添加第二个名为 SECOND_MAILER_URL 的变量。它会被上面的配置拾取。
猜你喜欢
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 2019-11-02
相关资源
最近更新 更多