繁体   English   中英

在Symfony 1.4中配置邮件程序 - 如何在管理面板中,而不是在factory.yml?

[英]Config mailer in Symfony 1.4 - how in admin panel, not factories.yml?

如何在Symfony的管理面板中配置电子邮件? 默认我必须在文件factories.yml中设置它:

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:   ~
        password:   ~

我想在管理面板中设置主机,端口,加密,用户名和密码,并将其保存在我的数据库中。 那么如果我发送邮件,怎样才能从数据库中获取这些数据呢?

    $message = $this->getMailer()->compose(
      array('jobeet@example.com' => 'Jobeet Bot'),
      $affiliate->getEmail(),
      'Jobeet affiliate token',
      <<<EOF
Your Jobeet affiliate account has been activated.

Your token is {$affiliate->getToken()}.

The Jobeet Bot.
EOF
    );

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

我可以从数据库中获取此数据:)但我不知道如何写入getMailer()。

配置邮件程序时会触发事件。

$dispatcher->notify(new sfEvent($this, 'mailer.configure'));

因此,您可以在此事件上添加侦听器,检索邮件程序对象,然后重新配置它。

或者,如此片段中所述,您可以手动构建对邮件程序的调用并定义如何设置配置(并且在任务中使用getMailer的优势): http ://snippets.symfony-project.org/snippet / 377

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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