在Symfony 2中发送文本普通标题

max*_*max 6 php symfony

我有一个动作,让客户预览系统电子邮件,我想发送text/plain明文版电子邮件的标题.

我试图遵循Symfony文档:Symfony部分中的请求和响应.然而,text/html无论我做什么,我的控制器都会发送内容类型.

这是我的行动:

function showAction($action = null, $format = null){

   $locale = $this->get('session')->getLocale();
   $format = $this->getRequest()->get("format");
   $format = isset($format) ? $format : 'html';


   if ($format === 'text'){
       $response = new Response();
       $response->headers->set('Content-Type', 'text/plain');
       $response->sendHeaders();

   }

   $view = sprintf('MyBundle:Email:%s.%s.%s.twig', 
         $action,$locale,$format);

   return $this->render($view, array());
}
Run Code Online (Sandbox Code Playgroud)

那么如何发送文本普通标题以及我哪里出错?

Ino*_*ryy 13

您需要在渲染调用中添加$ response

return $this->render($view, array(), $response);
Run Code Online (Sandbox Code Playgroud)