2012-09-11 12 views
6

मैं symfony2 ढांचे के साथ प्रयोग कर रहा हूं और मैं स्विफ्टमेलर और टहनियों का उपयोग करके ईमेल भेजने की कोशिश कर रहा हूं। समस्या यह है कि, मेरे वर्तमान कार्यान्वयन के साथ, ईमेल HTML में भेजा जाता है (आप टैग, सबकुछ देख सकते हैं)।स्विफ्टमेलर // ट्विग ईमेल सही ढंग से प्रतिपादन नहीं कर रहा है

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%} 

क्या मैं गलत कर रहा हूँ

यहाँ नियंत्रक मैं उपयोग कर रहा हूँ है?

उत्तर

14

आपको इस तरह सेटबॉडी() विधि को कॉल करके, शरीर के सामग्री-प्रकार को निर्दिष्ट करना होगा।

$message->setBody($messageBody, 'text/html'); 

अधिक जानकारी के लिए देखें: http://swiftmailer.org/docs/messages.html#setting-the-body-content

संबंधित मुद्दे