Hi community,
I’m trying to insert raw HTML into an email using a personalized token. However, it is being rendered as plain text, not HTML. This is similar to the issues discussed here and here, but for some reason, it is not working for me.
For my use case, I want to insert HTML generated by an AI Assistant in the middle of the email.
I’ve tried different approaches, such as a custom module and HTML templates, but none of them worked.
I might have made some mistakes. I would appreciate any help. Is there some way how to debug this?
Hey @JiriS, thank you for reaching out!!
To fix HTML rendering as plain text in your HubSpot marketing email with personalized tokens, ensure you are correctly using HubSpot’s personalization tokens. Verify that your email’s content type is set to text/html, and use inline styles for better rendering consistency across different email clients.
Inspect the raw source of the email for any character escaping or incorrect placements. Start with simplified HTML content and gradually add complexity to identify any issues. Ensure any custom modules or templates you are using output the HTML correctly.
To our top experts @Anton and @DanielSanchez do you have any other recommendations for @JiriS matter?
Thank you,
Pam
@PamCotton Thank you very much for your response and pointers.
I admit I haven’t added many details about what I have tried and how. I didn’t want to make the earlier post too long. Based on your suggestions:
I created a new email. Marketing → Emails → Create → Automated → Start from Scratch
Attempt 1
Add Edit Text field → source edit → add HTML
<h1>Dear {{ contact.firstname }},</h1>
<p>Here is sales advisor answer: {{ contact.advisor }}</p>
Contact settings:
- contact.firstname: Jiri
- contact.advisor: Visit our <a href=“Apify Store - 49,000+ web scraping and automation tools · Apify”>Apify Store</a>
When I sent a test email, the HTML was not rendered correctly:
(truncated for clarity)
Content-Type: multipart/alternative; boundary="----=_Part_442549_36597561.1718197900580"
------=_Part_442549_36597561.1718197900580
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Here is our sales advisor answer: Visit our <a href=3D"https://apify.com/store"=
>Apify Store</a>=20
------=_Part_442549_36597561.1718197900580
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<p>Here is our sales advisor answer: Visit our <a href=3D"https://apify.com/store">Apify Store</a>=20
Attempt #2
Modify HTML to: `{{ contact.advisor | safe }}` or `{{{ contact.advisor }}}` - not working.
Attempt #3
Create a custom module → add field rich text and in the field fill `{{ contact.advisor }}`.
Add the module in the email → send test email → the same result as in the Attempt#1
Attempt #4
Create a custom module → add field rich text and in the field fill `{{ contact.advisor }}`.
In the custom module enter the following:
{% inline_rich_text field="richtext_field" value="{{ module.richtext_field }}" %}
Or the following:
{{ contact.advisor | safe }}
Upon examining the emails, I’m getting the same results as in Attempt 1.
I think there is some important think I’m missing.
Should I provide more information?
Is there some way to see what is actually happening?
After multiple failed attempts, a key insight came from a discussion with a @matt_scott . The personalized token values were being escaped and surrounded by <p> tags when edited in the portal, making it impossible to unescape properly.
Instead of editing the property directly in the portal, use the HubSpot API to set the HTML content. This prevents the HTML from being escaped or wrapped in <p> tags.
Including in the email:
Since the rich text field cannot be included in the form, create a workflow to copy the content from a multi-line field to the rich text field.
That’s it. A big thank you to @matt_scott for the invaluable help
Pleased to help
Could you possibly explain this further?
I have a personalization token that includes HTML and it is working great in sales emails, but not in marketing.
Ex:
<a href=www.google.com>CLICK HERE</a>
In sales emails, I am seeing the CLICK HERE with the link attached to the words.
In marketing emails, I am seeing the raw HTML code.
Is this similar to the issue you had? Any insights?
For me, the problem was that the HTML content was not saved properly in the personalized token; that was the issue. Once it was fixed, it started to work.
Since it is working for you with a different email, it seems that the problem is within the sales email (which you have likely figured out yourself). The only advice I can offer now (though it may not be very helpful) is to compare the two emails. Try stripping down the sales email to identify any issues.