function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chuck TomlinsonChuck Tomlinson 

Only partial AMPscript functionality in EMail template? Or is my code wrong?

Hello,
I am composing an email 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*/
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.
 
Best Answer chosen by Chuck Tomlinson
Chuck TomlinsonChuck Tomlinson
Resolved:
- Use AttributeValue() instead of RequestParameter().
- Check for empty @emailaddr