Take the 2-minute tour ×

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

  class: sfMailer
    logging:           %SF_LOGGING_ENABLED%
    charset:           %SF_CHARSET%
    delivery_strategy: realtime
      class: Swift_SmtpTransport
        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?

      array('jobeet@example.com' => 'Jobeet Bot'),
      'Jobeet affiliate token',
Your Jobeet affiliate account has been activated.


The Jobeet Bot.


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

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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

share|improve this answer

Your Answer


