2012-06-21 54 views
4

我想,當電子郵件是我的Symfony2應用程序內發送,命名發件人如何在電子郵件發件人上輸入姓名?

Administrator <[email protected]> 

我在parameters.ini嘗試:

mailer_from  = {"[email protected] : Administrator"} 

這似乎可以這樣做因爲在SimpleMessage.php我們確實有:

/** 
    * Set the sender of this message. 
    * This does not override the From field, but it has a higher significance. 
    * @param string $sender 
    * @param string $name optional 
    * @return Swift_Mime_SimpleMessage 
    */ 
    public function setSender($address, $name = null) 
    { 
    if (!is_array($address) && isset($name)) 
    { 
     $address = array($address => $name); 
    } 

    if (!$this->_setHeaderFieldModel('Sender', (array) $address)) 
    { 
     $this->getHeaders()->addMailboxHeader('Sender', (array) $address); 
    } 
    return $this; 
    } 

所有的事情我在parameters.ini嘗試失敗編輯。你知道我做錯了嗎?

回答

3

這似乎可以這樣做,因爲在SimpleMessage.php我們有

嗯,這是可以設置的名字,但並沒有什麼表示,你可以使用配置設置。

SwitfMailerBundlephp app/console config:dump-reference SwiftmailerBundle)可用配置的快速倒將返回:

Default configuration for "SwiftmailerBundle" 
swiftmailer:   
    transport:   smtp 
    username:    ~ 
    password:    ~ 
    host:     localhost 
    port:     false 
    encryption:   ~ 
    auth_mode:   ~ 
    spool:     
     type:     file 
     path:     %kernel.cache_dir%/swiftmailer/spool 
    sender_address:  ~ 
    antiflood:    
     threshold:   99 
     sleep:    0 
    delivery_address:  ~ 
    disable_delivery:  ~ 
    logging:    true 

正如你所看到的,有sender_address被傳遞到ImpersonatePlugin.php

我不知道,你就可以設置一個名稱,但標準的方式,rawly,是使用形式的字符串:如果它不

「管理員」

不工作,這可能意味着,你會有一些工作,寫一個真正的EmailManager。

SwiftMailerBundle實際上只是SwiftMailer庫的集成,它是一個庫,而不是「管理器」。

+1

這就是爲什麼我寫了EmailManager,它在parameters.ini中獲取我想要的配置。感謝您的提示 –

+1

看起來有一個開放的PR這個配置功能:https://github.com/symfony/SwiftmailerBundle/issues/94 +1 – webDEVILopers

相關問題