2012-11-13 2 views
8

전자 메일로이 응답 받기 "HTTP/1.0 200 OK 캐시 제어 : no-cache Content-Type : text/html; charset = UTF-8 날짜 : 2012 년 11 월 13 일 화요일 04:56:14 GMT " 또한이 방법은, 즉 서비스 "이메일"에 속해 있음을 유의symfony 2의 신속한 메일러를 사용하여 전자 메일을 받았지만 불필요한 응답을 전자 메일로 받음

public function sendEmail($subject, $template, $templateParams) 
    { 
     $userEmail = $this->session->get('email'); 
     $name = $this->session->get('name'); 
     $adminEmail = $this->container; 
     $templateParams['username'] = $name; 
     $message = \Swift_Message::newInstance() 
       ->setSubject($subject) 
       ->setFrom($adminEmail) 
       ->setTo($userEmail) 
       ->setBody($this->templating->render('SocialDonSocialBundle:Email:'.$template,$templateParams), 'text/html'); 
     $this->mailer->send($message); 

:

여기 내 코드입니다. 나는 이메일을 보낼 책임이있는 "이메일"서비스를 만들었습니다. 아무도 그 문제가 뭔지 압니까?

+0

헤더를 가져 오는 이유가 없습니다. 템플릿이 출력 헤더 자체와 같이 이상하게 작동합니까? – lifo

+0

나는 또한 그것을 얻고있다. 고쳐 봤어? – dextervip

답변

25

render()는 항상 헤더를 표시하므로 render() 대신 renderView()를 사용해야합니다. .

$content = $this->container->get('templating')->renderResponse(
     'YOUR_TEMPLATE.twig', 
     templateParams) 
    )->getContent(); 

이나 질문처럼 동일한 값을 : 버전 2.5 등 Symfony2 최신 버전에서

+1

나는 똑같은 문제가 있었다. 이 답변을 주셔서 감사합니다 –

+0

그것은 완벽하게 해결합니다. 감사. –

2

*

용액 renderResponse을 사용하고 그 위에) (a의 getContent 할 것이다 :

$this->templating->renderResponse('SocialDonSocialBundle:Email:'.$template,$templateParams)->getContent(); 
관련 문제