在Symfony 1.4中配置mailer -如何在管理面板中,而不是分解。

时间:2022-07-06 07:27:10

How can i do configuration of emails in admin panel in Symfony? Default i must set this in file factories.yml:

在Symfony的管理面板中如何配置电子邮件?默认情况下,我必须将其设置为文件分解。

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().

我可以从数据库中获取这些数据:)但是我不知道如何写进getMailer()。

1 个解决方案

#1


4  

There is an event fired when the mailer is configured.

在配置mailer时触发一个事件。

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

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

因此,您可以在此事件中添加一个侦听器,检索mailer对象并重新配置它。

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

或者,正如在这段代码中所描述的,您可以手工构建对mailer的调用,并定义如何设置配置(并在任务中使用getMailer): http://snippets.symfony-project.org/snippet/377。

#1


4  

There is an event fired when the mailer is configured.

在配置mailer时触发一个事件。

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

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

因此,您可以在此事件中添加一个侦听器,检索mailer对象并重新配置它。

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

或者,正如在这段代码中所描述的,您可以手工构建对mailer的调用,并定义如何设置配置(并在任务中使用getMailer): http://snippets.symfony-project.org/snippet/377。