2016-08-28 23 views
0

下面的代碼工作我使用的服務器(HOSTEUROPE的WebPack)上:與Swiftmailer控制的Sendmail中的Symfony

mail('[email protected]', 'some subject', 'sendmail is working', 'From: [email protected]', ""); 

下面的代碼是不是:

$message = \Swift_Message::newInstance() 
    ->setSubject('some subject') 
    ->setFrom('[email protected]') 
    ->setTo('[email protected]') 
    ->setBody('sendmail via swiftmail is working'); 
$mailer = $this->get('mailer'); 
$logger = new Swift_Plugins_Loggers_ArrayLogger(); 
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($logger)); 
$mailer->send($message); 

而且在$記錄器寫入這個錯誤:

++ Starting Swift_Transport_SendmailTransport 
<< 
!! Expected response code 220 but got code "", with message "" (code: 0)" 
    ... 

我的配置是:

swiftmailer: 
    transport: "sendmail" 
    sender_address: "[email protected]" 

我不明白爲什麼一個正在工作,另一個是因爲,據我所知,這個電話應該是相同的。

回答

0

問題是Sendmail傳輸不會發送From標題(如預期的那樣)。 使用「郵件」作爲運輸工作對我來說:

swiftmailer: 
    transport: "sendmail" 
    sender_address: "[email protected]" 

希望這可以幫助具有和HOSTEUROPE的sendmail /發送郵件麻煩別人。

0

如果你的sendmail和symfony一起使用,可能會發生你必須通過一些額外的選項。例如:

'/usr/sbin/sendmail -t -i'

要找出哪些選項必須被傳遞,在服務器上創建一個phpinfo.php

<?php 
phpinfo(); 
> 

運行它,發現它與啓動項:

sendmail_from 
sendmail_path 

其中任何一個都會顯示/usr/sbin/sendmail -some_options

爲了讓它在symfony中工作,你不能直接粘貼到config.yml - 至少在我的經驗。

打開了services.yml並添加:

swiftmailer.mailer.default.transport: 
    class:  Swift_SendmailTransport 
    arguments: ['/usr/sbin/sendmail -t -i'] 

哪裏arguments是從上面的PHP入門的路徑。

然後設置config.yml到:

swiftmailer: 
    transport: sendmail 

或者,如果你喜歡獨立開發和生產線ENV,將其粘貼在其中的一個。