Hello there!
I've got a {{lead.Email}} in my database. We send out emails to our leads with an links, and the href for the anchor tags contain the email address as a URL query parameter like so-
...
<a href="https://abc.domain.com/route?email={{lead.Email}}">My Cart</a>
...
We've observed a problem with this- some leads enter their email with a + sign, and this sign remains intact in the URL (it should ideally be parsed into a %2B in the URL). How can I do this?
I've tried writing VTL scripts for this-
Script (my.parsedEmail):
#set($email = ${lead.Email})
#if($email=="")
#set($email = "null")
#end
$email.replace("+","%2B"))
Email:
...
<a href="https://abc.domain.com/route?email={{my.parsedEmail}}">My Cart</a>
...
This approach resulted in the entire VTL script getting dumped into the URL.
https://abc.domain.com/route?email=&mkt_tok=long_string#set($email%20=%20${lead.Email})#if($email==%22%22)null#end#if($email!=%22%22)$email.replace(%22+%22,%22%2B%22))#end
Then, I learned that we're supposed to get the entire <a> tag out of the script in one piece, with the https:// protocol in the tag and the URL in a variable.
This is my latest script-
## Generate the right email address (replace + with %2B)
#set($email = ${lead.Email})
#if($email=="")
#set($email = "null")
#end
#set($email=$email.replace("+","%2B"))
## define button styles
#set($styles="some_inline_button_styles")
## generate the link
#set($url="abc.domain.com/route?referral=marketo&email=$email")
## The line that gets injected into the email
<a rel="noopener" style="$styles" target="_blank" href="https://$url">Complete My Application</a>
The link generated was the most ridiculous one yet-
https://%24url/?mkt_tok=long_string
I've been stuck for a couple of days, how do I get this to work?
Thanks in advance!
Solved! Go to Solution.
A native {{lead.token}} is not URL-safe and any such link needs to be emitted from Velocity.
But don’t roll your own URL-encoder, there’s one built into EscapeTool.
#set( $email = $lead.Email )
#if( $email.isEmpty() )
#set( $email = "null" )
#end
## define button styles
#set( $styles="some_inline_button_styles" )
## generate the link
#set( $urlNoProto ="abc.example.com/route?referral=marketo&email=${esc.url($email)}" )
## The line that gets injected into the email
<a rel="noopener" style="$styles" target="_blank" href="https://${urlNoProto}">Complete My Application</a>
Also remember not to use another company’s actual domain. In demo code use example.com.
A native {{lead.token}} is not URL-safe and any such link needs to be emitted from Velocity.
But don’t roll your own URL-encoder, there’s one built into EscapeTool.
#set( $email = $lead.Email )
#if( $email.isEmpty() )
#set( $email = "null" )
#end
## define button styles
#set( $styles="some_inline_button_styles" )
## generate the link
#set( $urlNoProto ="abc.example.com/route?referral=marketo&email=${esc.url($email)}" )
## The line that gets injected into the email
<a rel="noopener" style="$styles" target="_blank" href="https://${urlNoProto}">Complete My Application</a>
Also remember not to use another company’s actual domain. In demo code use example.com.
This works- thank you!