0

I am composing an email in ExactTarget/MarketingCloud and I am successfully able to get the recipient's email address (actually I just need the domain) into the email with:

%%=Substring(emailaddr,IndexOf(emailaddr,'@'),100)=%%

So, I'm sure that Substring() and IndexOf() DO work in an email [as opposed to microsite and landing pages -- I hear they have different functionality].. but my code that works OUTSIDE of an AMPScript block doesn't work INSIDE? as follows:

%%[

/* NOTE: commented out vars?! */

/* var @EMailCount, @lookupDomain */<br>
set @lookupDomain = "homenwork.com"

/* I want this to work to get the recipient's email address to parse inside my AMPscript block */

/* set @emailaddr = RequestParameter("emailaddr") */

/* these don't work in here?! do I need some 'functions' feature enabled or something?! weird

set @nPos = IndexOf(@emailaddr,"@")

set @nPos = Add(@nPos,1)

set @lookupDomain = Substring(@emailaddr,@nPos,100)

*/

set @EMailCount = Lookup("CRTdebug", "CounterField", "EMailDomain", @lookupDomain)

]%% 

EmailCount is %%=v(@EMailCount)=%%

Please note that the vars are commented out because something is preventing that syntax because it gave me some error about not having the required comma, but as you can see, there are commas.. I commented them out and the code seems to run fine with me setting values to non-declared variables, which is weird, but whatev.

1 Answer 1

1

RequestParameter() is the wrong function to retrieve the email address in an email. AttributeValue() is what you want...and you should be checking to see if it's empty or not before trying your string functions.

Try something like this:

%%[

var @EMailCount, @lookupDomain
set @lookupDomain = "homenwork.com"

set @emailaddr = AttributeValue("emailaddr")

if not empty(@emailaddr) then

    set @nPos = IndexOf(@emailaddr,"@")
    set @nPos = Add(@nPos,1)
    set @lookupDomain = Substring(@emailaddr,@nPos,100)

    set @EMailCount = Lookup("CRTdebug", "CounterField", "EMailDomain", @lookupDomain)

else

    set @EMailCount = 0

endif

]%% 

EmailCount is %%=v(@EMailCount)=%%
7
  • OK that makes sense - I'll try that.. In the meantime, do you know what this is when I try to declare variables? Unable to generate preview There is an error in your email. Please contact your customer service representative. Error 1: Invalid Script VAR Statement An expected comma is not found in the varible declaration. Invalid Content: var \@EMailCount, \@lookupDomain I thought it was because I wasn't declaring them..
    – CRT
    Oct 20, 2016 at 1:32
  • that really didn't format well :-S
    – CRT
    Oct 20, 2016 at 1:33
  • Your variable declarations look fine, except for that errant <br>. Oct 20, 2016 at 1:37
  • Yes, the checking for it being empty part worked well too.
    – CRT
    Oct 20, 2016 at 2:16
  • 1
    you can just use the Domain() ampscript function instead of substring and index of - help.marketingcloud.com/en/documentation/ampscript/… Oct 20, 2016 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .