Email Marketing Tool

HadarZohar
Participant

Link URL's using email={{contact.email}} with + in the email address

I'm trying to use {{contact.email}} in a link but it doesn't work if the email address contains "+" in it.

We use "+" to test it with our email address: name+test@comapnyname.com

The email format in the example isn't working with {{contact.email}}, do you have any idea how to fix it? 

0 Upvotes
2 Replies 2
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Link URL's using email={{contact.email}} with + in the email address

Hello @HadarZohar 

plus sign (+) is a special character in URLs. It is used to encode other characters, such as spaces. So, when you use {{contact.email}} in a link, the plus sign is encoded as %20. This means that the email address in the link will be something like:

mailto:name%2btest@comapnyname.com

This email address will not work, because the recipient's email client will not be able to decode the plus sign.

To fix this, you need to replace the plus sign with a space in the email address before you use it in the link. You can do this using the following code:

var email = {{contact.email}};
var encodedEmail = email.replace("+", " ");

var link = "mailto:" + encodedEmail;

This code will replace all of the plus signs in the email address with spaces. Then, it will create a link with the encoded email address.

Here is an example of how this code would work:

var email = "name+test@comapnyname.com";
var encodedEmail = email.replace("+", " ");

var link = "mailto:" + encodedEmail;

console.log(link)
; // "mailto:name test@comapnyname.com"

As you can see, the plus sign in the email address has been replaced with a space, and the link now works.

Digital Marketing & Inbound Expert In Growth Hacking Technology
HadarZohar
Participant

Link URL's using email={{contact.email}} with + in the email address

Thanks.
I think I didn't explain myself right or you didn't understand me properly
🙂
I will explain:
We don’t want to use the “mailto”, we want to add the email as a URL
parameter, for example, company.com/some-url?email=email+foo@company.com
which needs to be translated to
company.com/some-url?email=email%2bfoo@company.com
0 Upvotes