douhuan1908 2012-04-16 09:03
浏览 32
已采纳

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

How can i do configuration of emails in admin panel in Symfony? Default i must set this in file 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:   ~

I would like set host, port, encryption, username and password in admin panel and keep this in my database. So how can i get this data from database if i send mail?

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

I can get this data from database :) but i dont know how to write in to getMailer().

  • 写回答

1条回答 默认 最新

  • dtfbj24048 2012-04-16 09:22
    关注

    There is an event fired when the mailer is configured.

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

    So you can add a listener on this event, retrieve the mailer object, and re-configure it.

    Or, as describe in this snippet, you can built manually the call to the mailer and define how you set the config (and got the advantage to use getMailer in a task): http://snippets.symfony-project.org/snippet/377

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧