2012-09-11 3 views
6

symfony2 프레임 워크를 실험 중이며 swiftmailer 및 twig를 사용하여 전자 메일을 보내려고합니다. 문제는, 현재의 구현으로, 이메일은 html로 보내진다 (모든 것을 볼 수있다). 이메일이 사용Swiftmailer // Twig 전자 메일이 올바르게 렌더링되지 않습니다.

public function formularioAction() 
{ 
    $enquiry = new Enquiry(); 
    $form = $this->createForm(new EnquiryType(), $enquiry); 

    $request = $this->getRequest(); 
    if($request->getMethod() == 'POST'){ 
     $form->bindRequest($request); 

     if($form->isValid()){ 

      $message = \Swift_Message::newInstance() 
        ->setSubject('Mail from the App') 
        ->setFrom('[email protected]') 
        ->setTo('******@gmail.com') 
        ->setBody($this->render('AcmeDemoBundle:Demo:email.html.twig')); 

      $this->get('mailer')->send($message); 
      //end of mail sending 

      //redirect - it's important to prevent users from reposting the form if 
      //they refresh the page 
      return $this->redirect($this->generateUrl('_formulario')); 
     } 
    } 
    return $this->render('AcmeDemoBundle:Demo:formulario.html.twig', array('form' => $form->createView())); 
} 

그리고 나뭇 가지 템플릿 :

{% extends "AcmeDemoBundle::layout.html.twig" %} 

{% block title "Email de teste" %} 

{% block content%} 
<H1>Este é um render de um email de teste!</H1> 
{% endblock%} 

내가 뭘 잘못 여기에

내가 사용하고 컨트롤러입니까?

답변

관련 문제