【问题标题】:set default FROM for SwiftMailer in Symfony在 Symfony 中为 SwiftMailer 设置默认 FROM
【发布时间】:2011-11-16 13:10:55
【问题描述】:
mailer:
  class: sfMailer
  param:
    logging:           %SF_LOGGING_ENABLED%
    charset:           %SF_CHARSET%
    delivery_strategy: realtime
    transport:
      class: Swift_SmtpTransport
      param:
        host:       localhost
        port:       25
        encryption: ~
        username:   user@gmail.com
        password:   pass

这是 swift mailer 的配置。如果我想发送电子邮件,那么我必须使用:

    $message = $this->getMailer()->compose(
      array('user@gmail.com' => 'user'),
      $affiliate->getEmail(),
      'Jobeet affiliate token',
      body
    );

    $this->getMailer()->send($message);

我想设置这条线:

array('user@gmail.com' => 'user'),

自动。如果我在配置中更改 user@gmail.com,那么我想在这一行中自动更改。我在我的网站的几个地方有邮件。 有可能吗?

可能和 app.yml 中的一样?

感谢帮助

【问题讨论】:

    标签: php symfony1 symfony-1.4 swiftmailer


    【解决方案1】:

    你可以做下一个:

    在 app.yml 中:

    all:
    from_mail: user@gmail.com
    

    然后制作:

    array(sfConfig::get("app_from_mail") => 'user'),
    

    【讨论】:

    • 我认为,应该在 factory.yml 中配置邮件程序。如果您在 settings.yml 中配置了邮件程序,可以尝试(sfConfig::get("settings_mailer_transport_param_username")
    【解决方案2】:

    如果你使用 ≥ 2 的 Symfony 版本,你可以执行以下操作。

    通过在控制台中运行composer require finesse/swiftmailer-defaults-plugin 来安装Swift Mailer Defaults plugin。然后将以下代码添加到您的 yml 配置中:

    services:
        # Swift Mailer plugins
        app.swiftmailer.defaults_plugin:
            class: Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin
            tags:
                - { name: swiftmailer.default.plugin }
            arguments:
                $defaults:
                    from:
                        user@gmail.com: user
                    # You can add more default properties here, e.g. sender, reply to
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      相关资源
      最近更新 更多