Replace First Name Contact in Email With A Default Text When There Isn't a First Name in the Contact

Regular Contributor

Hi there,


I am new to this community, so I do apoligize if this question has been asked and answered. I did a search, and I didn't quite find the answer I was looking for. I am a bit new to scripts and Hubspot so any guidance is greatly appreciated. 


My problem:

I recently created an email to send out, and the contact list that I have is over 5000. Not all of the 5000 contacts has a first name so when I sent out the email, the contact with a first name showed up as "Hi John," while the contacts without a first name had "Hi (blank),." I found an IF/Else script from another post, but it didn't quite work because it would say "Hey There" even when there was a first name in the contact email. The first name got override by the "Hey There" text that I entered in. I hope I explained it well. Please let me know if you have any questions.


Thank you!


This was the script I found on this Hubspot post

{% set fname = contact.firstname|default('') %}

{% if fname|list|length > 2 %}

Dear {{contact.firstname}},

{% else %}

Dear Valued Member,

{% endif %}

7 Replies 7
Community Superstar

>>Replace First Name Contact in Email With A Default Text When There Isn't a First Name in the Contact


Welcome @Zoomi.

mfjlabs-screenshot-HubL supported if statements-20190826-181813.pngHubL Reference - If statements

- see HubL Reference - If statements


Instead, you'll want to consider creating/changing the default value for your HubSpot Contact First Name personalization token to something like 'there'. That way, when the value is blank, the default will kick in and read something like ...


Hi there,

This message is just for you ...


- see Create default values for your personalization tokens

Regular Contributor

Hi Frank,


Thank you so much for the helpful information! This helps a lot!


This next question may sound dumb, but I was wondering how I would setup "Hi," when there isn't a first name? Right now, I have Hello "Firstname" and I add a comma after "FirstName" so it looks like Hello FirstName,. What if I decide not to have a default value as "There" but I only want it to say "Hello,"(but I want the comma next to 'Hello') instead. Currently, when there isn't a FirstName, it shows up as "Hello ," how would I fix this issue?


Thank you again for your help!

- Kevin

Occasional Contributor

I'd also like to know about this! This is an age-old issue with personalization, there MUST be a workaround.

Occasional Contributor

I would like to know the solution for this issue as well!

Sometimes, instead of saying "Hi there," to people without a first name, it's probably better to simply say "Hi,".


In addition, what if when a contact's first is not in good writing, for example, john or jOHN instead of John. Many of our contacts' first name are like that. What do you guys do when your database in such lower quality?


Thank you.

Community Manager

To add my two cents here, even if you don't have a value for the default value, it would create a space between the hello and the comma ("hello ,"); if you are looking to use a personalization token, I would say it comes down to personal and brand preference for whether "hello there," / "hi friend" / "hi again" or "hi ," / "hello ," "dear ,".


@Bryantworks@MatthewShepherd@AM8 do you have any favorite personalization tokens for default values? 


Thank you,

Did my post help answer your query? Help the Community by marking it as a solution
Top Contributor

@jennysowyrda : Yep, I agree with you, if we do use a personalization token then there would be a space even if the default value is empty. 

As a company we usually just go with Dear , or Hello , and avoid using terms like Hi there,. 


Another workaround that I use is that sometimes based on the content, I drop the word Hi or Dear completely. I just start my email as: 


Congratulations on < Company Name > being named as one of the top 10 startups to look out for in 2019.  In the light of this development, I am sure you are facing the challenge of ..... blah blah blah 

@ClaireHsu : Bad data is a big issue. BIG! The only way to fix it is to implement data hygiene. But in the meantime you can try sending emails without personalization tokens. Just say Hi, or Hello, . 
Getting a name spelled wrong or typed in wrong formatting really kills the "human" aspect of the email and hurts the campaign. 

Hope this helps
Thank you.
#Did my post help answer your query? Help the Community by marking it as a solution.
Regular Advisor

Thanks for the tag @jennysowyrda !




We typically use our tokens to match our businesses:


Hey Pet Parent,

Hey HubSpotter,

Hey members,


And so on, the beauty of the contact tokens is the personability, but even more so you can do it as defaults by moreso general terms for your audience!