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

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 在Symfony 2中发送文本普通标题脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个动作,让客户预览系统邮件,我想发送明文版电子邮件的文本/普通标题.

我试着按照Symfony docs : Requests and Responses in Symfony部分.但是,无论我做什么,我的控制器都会发送文本/ 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());
}

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

您需要在渲染调用添加$response
return $this->render($view,array(),$response);

脚本宝典总结

以上是脚本宝典为你收集整理的php – 在Symfony 2中发送文本普通标题全部内容,希望文章能够帮你解决php – 在Symfony 2中发送文本普通标题所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。