2012-09-07 20 views
5

默認情況下,我使用假脫機郵件解決方案在我的網頁中發送簡報。但我也需要立即發送電子郵件。所以我用this solution在Symfony2中使用假脫機程序併發送即時電子郵件的其他郵件服務 - 奇怪標頭

如果我發送時事通訊一切都很好。但是當我使用

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

我收到電子郵件的開頭有一些文字前面加上:

HTTP/1.0 200 OK緩存控制:無緩存的Content-Type:text/html的; charset = UTF-8日期:2012年9月7日星期五16:19:06 GMT

如何清除此錯誤?

回答

7

我敢打賭,你正在嘗試發送一個Response對象。

new Response(); 

它去__toString()

public function __toString() 
{ 
    $this->prepare(); 

    return 
     sprintf('HTTP/%s %s %s', $this->version, $this->statusCode, $this->statusText)."\r\n". 
     $this->headers."\r\n". 
     $this->getContent(); 
} 

這是因爲:

$this->render('template.html.twig'); 

返回響應,以避免使用:

$response = $this->render('template.html.twig'); 
$text = $response->getContent(); 

問候, 最大

+0

如果你w應該賭上它的彌蟲,你會成爲一個米勒。謝謝:) – Tom

+0

不客氣:) –

+0

最大,做得好。它很棒! – medina

0

其他更多鈔票解決問題的方法是使用templating服務,而不是$this->render()

<?php 
$body = $this->get('templating')->render('template.html.twig'); 
1

使用

$content = $this->renderView('template.html.twig'); 

,而不是

$content = $this->render('template.html.twig'); 

渲染返回響應

相關問題