Magento – How to render data type html in template email magento2

emailemail-templatesmagento2

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

Best Answer

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

Related Topic