12

I have email template in Magento 2: email-template.html

{{template config_path="design/email/header_template"}}

{{trans "%body" body=$data.body}}

{{template config_path="design/email/footer_template"}} 

But in variable $data.body is code html not text:

$data.body = `
<table width="100%"> 
  <tr> 
     <td>Name: </td> <td>Join Xanka </td>
  </tr> 
  <tr> <td>Email: </td> <td>xanka@gmail.com</td> </tr>
  {{depend Test Send}} 
  <tr> <td>Subject: </td> <td>Test Send</td> </tr>
  {{/depend}} 
  <tr> <td>Message: </td> <td>we try send email use to test.</td> </tr>
</table>

So how to render code html when send send email. Many thank!

This is result when excuse code print_r($this->_message->getBody()); in sendMessage() function:

enter image description here

17

I change {{trans "%body" body=$data.body}} to {{trans "%body" body=$data.body|raw}}. it render success.

7

Use '|raw' with you param variable.

example: '{{var data|raw}}'

where data is param variable which passed to template and contains value which is HTML code. data=

4

Along with {{trans "%body" body=$data.body}} to {{trans "%body" body=$data.body|raw}}.

Do remember to change type="text" to type="html" in email_templates.xml, otherwise you'll get plain HTML in your mails.

  • Thank you so much for the tip type="html". I just made a chilly mistake, It ruins around half an hour! – DRAJI Feb 22 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.