2015-11-13 58 views
0

我使用的是SwiftmailerBundle 2.3.8附帶的Symfony 2.7。在Symfony2中爲Swiftmailer設置default_mailer不起作用

這是我的配置

swiftmailer: 
    mailers: 
     spool_mailer: 
      transport: "%mailer_transport%" 
      host:  "%mailer_host%" 
      username: "%mailer_user%" 
      password: "%mailer_password%" 
      spool: 
       type: file 
       path: %kernel.root_dir%/spool 

     instant_mailer: 
      transport: "%mailer_transport%" 
      host:  "%mailer_host%" 
      username: "%mailer_user%" 
      password: "%mailer_password%" 
    default_mailer: spool_mailer 

我想用2個郵寄,一個後臺,一個用於發送即時他們。

這兩個命令可以正常工作,電子郵件可以被假脫機或立即發送。

$this->get('swiftmailer.mailer.instant_mailer')->send($email); 
$this->get('swiftmailer.mailer.spool_mailer')->send($email); 

然而,

$this->get('mailer')->send($email); 

不取default_mailer這是在我的情況下,後臺處理程序,但它即刻發送。我見過here這是可能的,但也許這個答案是不正確的。

我錯過了配置文件中的內容嗎?或者我不是在呼喚它?

+0

我**真的不知道**爲什麼,但我已經看到,聲明'default_mailer:spool_mailer'上面定義郵件的行將做到這一點。我也沒有任何支持文檔。但我相信這是值得的。 –

回答

0

即使使用symfony 2.6.8版本,我也會遇到同樣的問題。 我現在唯一找到的解決方案是:刪除default_mailer參數,並使用此名稱設置默認郵件程序,這是:默認。 所以,你的配置是這樣的:

swiftmailer: 
    mailers: 
     default: # your named spool_mailer 
      transport: "%mailer_transport%" 
      host:  "%mailer_host%" 
      username: "%mailer_user%" 
      password: "%mailer_password%" 
      spool: 
       type: file 
       path: %kernel.root_dir%/spool 

     instant_mailer: 
      transport: "%mailer_transport%" 
      host:  "%mailer_host%" 
      username: "%mailer_user%" 
      password: "%mailer_password%" 

從現在開始從$這個 - 得到的對象> getContainer() - >獲取( 'swiftmailer.mailer');將被定義爲默認的一個並沒有更多的象這樣的錯誤會顯示:

[Swift_TransportException]               
    Connection could not be established with host localhost [Connection refused #111] 

這個配置在我目前從事的項目爲我工作。

我希望它有幫助。