2016-06-21 72 views
1

我已經閱讀了幾篇文章,還介紹瞭如何在swiftmailer中包含2個不同的電子郵件,但是我收到一個錯誤,不知道爲什麼。Symfony 2.3 Swiftmailer - 2封電子郵件

這裏是我的配置:

//config.yml 
swiftmailer: 
    default_mailer: mailer 
    mailers: 
     mailer: 
      transport: smtp 
      host:  some.host1 
      username: some.username1 
      password: some.password2 
     mailer2: 
      transport: gmail 
      host:  some.host2 
      username: some.username2 
      password: some.password2 

我還創建了一個服務文件:

# app/config/services.yml 
    services: 
     mailer: 
      class:  AppBundle\Mailer 
      arguments: [sendmail] 
     mailer2: 
      class:  AppBundle\Mailer 
      arguments: [sendmail] 

和Controller我指的是既作爲:

$mailer = $this->get('mailer2'); 

//or 

$mailer = $this->get('mailer'); 

但只默認的郵件工程。在第二個郵包的情況下,我得到:

You have requested a non-existent service "mailer2". 

我怎樣才能解決這個問題?

回答

1

您不需要配置服務文件。

爲了得到第一個郵件:

$container->get('swiftmailer.mailer.mailer'); 

要獲得第二郵件:

$container->get('swiftmailer.mailer.mailer2'); 

若要獲取默認的郵件:

$container->get('swiftmailer.mailer'); 

查看文檔Using Multiple Mailers

+0

我讀了docum但卻完全錯過了'迅捷魔法師'。 '開頭的部分,感謝您注意,看起來它現在正在工作,謝謝。 – user3253748