Send HTML params in messageVersions

Hello,

I need to send parameters containing HTML tags in messageVersions params, but html format doesn’t work.

How to enable HTML tags in messageVersions params ?

Hello @gzai , thanks for posting on this community!

What do you mean by messageVersions?

Hello @ahudavert,

I mean like this

	$apiInstance = new Brevo\Client\Api\TransactionalEmailsApi(
	    new GuzzleHttp\Client(),
	    $config
	);

	$sendSmtpEmail = new \Brevo\Client\Model\SendSmtpEmail();
	$sendSmtpEmail['sender'] = [
		'email' => $campaignData['sender']['email'], 
		'name' => $campaignData['sender']['name'],
	];
	$sendSmtpEmail['subject'] = $campaignData['subject'];
	$sendSmtpEmail['htmlContent'] = $campaignData['htmlContent'];
	$sendSmtpEmail['messageVersions'] = [
		[
			"to" => [
				['email' => 'userA@email.com', 'name' => 'User A'],
			],
			"params" => [
				'employee_list' => "<table cellpadding=\"10\" cellspacing=\"0\" border=\"1\">
									  	<tr>
										    <th>Employee Name</th>
										    <th>Email</th>
									  	</tr>
									  	<tr>
										    <td>Employee A</td>
										    <td>Email Employee A</td>
									  	</tr>
									  	<tr>
										    <td>Employee B</td>
										    <td>Email Employee B</td>
									  	</tr>
									  	<tr>
										    <td>Employee C</td>
										    <td>Email Employee C</td>
									  	</tr>
									</table>",
			]
		],
	];

try {
	    $result = $apiInstance->sendTransacEmail($sendSmtpEmail);
	    print_r($result);
	} catch (Exception $e) {
	    echo 'Exception when calling TransactionalEmailsApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
	}

instead of converting to html it becomes plain text for params.employee_list

Ok clear, thanks.

Is the problem related to messageVersions or to params: have you tried to add html inside params even without messageVersions? If yes, did it work?

Yes, I’ve tried to add html inside params, it becomes plain text too

$sendSmtpEmail['params'] = [
    'employee_list' => "<table cellpadding=\"10\" cellspacing=\"0\" border=\"1\">
									  	<tr>
										    <th>Employee Name</th>
										    <th>Email</th>
									  	</tr>
									  	<tr>
										    <td>Employee A</td>
										    <td>Email Employee A</td>
									  	</tr>
									  	<tr>
										    <td>Employee B</td>
										    <td>Email Employee B</td>
									  	</tr>
									  	<tr>
										    <td>Employee C</td>
										    <td>Email Employee C</td>
									  	</tr>
									</table>",
];

The result :

image

Ok that’s what I thought, unfortunately: I don’t think HTML is authorized inside the parameters

maybe it can handle html tags in parameters, because htmlContent can handle html tags.
but there must be changes in main code

I think it’s more related to the nature of the field:

  • htmlContent can handle html tags because by essence it’s supposed to be HTML
  • but for params, as they are supposed to be « normal » inputs, I don’t think they’re supporting html tags

for parameters maybe indeed they are supposed to be normal inputs, and not supported html tags. but also does not support use CRLF (\r\n ).
I mean, if we can do a new line that’s enough for params value.

I see what you need.
Let me tag @Mohit in this thread, so that he’s aware of the need, even though I’m not sure it’s planned to make changes to the behavior of params soon

Thanks @ahudavert.

Yes, hopefully there are plan to make changes to behavior of params soon.

If you are using a template have you tried {% autoescape off %}{{params.employee_list}}{% endautoescape %}

It worked for me with html <br> tags in my parameters

2 Likes

wow, work like a charm.

I’ve tried using the html tags <br> and <table>. everything works.

Thanks @ShakesMcQuakes

thanks @ShakesMcQuakes for the insight, and @gzai for the link!