2012-09-11 30 views
6

Tôi đang thử nghiệm với khung công tác symfony2 và tôi đang cố gửi email bằng swiftmailer và twig. Vấn đề là, với việc thực hiện hiện tại của tôi, email được gửi bằng html (bạn có thể thấy các thẻ, mọi thứ).Swiftmailer // Twig email không hiển thị chính xác

Dưới đây là bộ điều khiển Tôi đang sử dụng:

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())); 
} 

Và cành lá mẫu email được sử dụng:

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

{% block title "Email de teste" %} 

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

am i làm gì sai?

Trả lời

Các vấn đề liên quan