2013-09-23 41 views
5

我目前正試圖讓Symfony2/Swiftmailer通過郵件發送提交表單的內容。我parameters.yml包含以下內容:配置Symfony2/Swiftmailer使用「sendmail -t」

mailer_transport: sendmail 
mailer_host: ~ 
mailer_user: ~ 
mailer_password: ~ 

由於我的服務器上sendmail的版本不支持-bs選項,該選項Swiftmailer似乎默認使用,我必須找到一種方式來告訴Symfony2的/ Swiftmailer使用改爲sendmail -tSwift_Transport_SendmailTransport似乎支持,但似乎沒有SwiftmailerBundle相應的配置選項。

我如何告訴Swiftmailer使用sendmail -t(最好通過配置)?

編輯2:現在,我使用

$message = \Swift_Message::newInstance() 
      […]; 

$transport = $this->get('swiftmailer.mailer.default.transport.real'); 
if ($transport instanceof \Swift_Transport_SendmailTransport) { 
    $transport->setCommand('/usr/sbin/sendmail -t'); 
} 

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

我一直在想,如果有更好的方式來做到這一點,雖然。

回答

6

這個配置應該工作。

mailer_transport: sendmail 
mailer_host: /usr/bin/sendmail # wherever your mail is 
#mailer_user: ~ 
#mailer_password: ~ 

如果還有問題,

A. check who are sending mail to [email protected] 
    1. console - check your permission to access sendmail 
    2. web - check web user like wwww-data can access sendmail 
B. check your mail log /var/log/maillog 
    When Symfony Swiftmailer send, 
    1. mail log has not been processed, then PHP side problem. 
    2. else if: send to outlook 
     it is TLS handshake problem, it might be from outlook tls handshake. 
     FYI, sendmail TLS is not working with outlook well. 

     add next line to /etc/mail/access 
     Try_TLS:wxy.com    NO 
    3. else: 
     Sorry, google with mail log error messages again . 
5

剛剛度過了一天就這一問題。

我更喜歡使用直配置這種事情,我發現這個工作:

# app/config/services.yml 
services: 
    swiftmailer.mailer.default.transport: 
    class:  Swift_SendmailTransport 
    arguments: ['/usr/sbin/sendmail -t']