Does anyone know why AMPscript variables won't work in the preheader? They will resolve in the send preview, but once the email is delivered they are blank.

If I use the same variables in both the subject line and preheader, the subject line variables resolve but the preheader variables do not once the email is delivered. This does not make sense to me and seems like a bug in SFMC. Wondering if anyone has a solution or work around.

These are ampscript variables... so the syntax is like this:

This is my variable: %%=v(@var)=%%

  • Are you initializing @var before assigning it? E.g. var @var set @var = "whee". Jan 19 '16 at 13:36

The issue is that in the fully built email the AMPscript block that sets the preheader variables is placed farther down in the file than where the preheader gets inserted.

SFMC will place the preheader block directly after the opening <body> tag. In order to have preheader variables render after the email deployment, your AMPscript block that sets these variables must be placed before the opening <body> tag. I put the block directly after the opening <html> tag.


Perhaps this is the issue: missing <head></head> tags in your email.

Preheader doesn't render in a Marketing Cloud email

Found via findsf.info


Relevant post: Create dynamic preheader in exacttarget

  • Thanks for the reply, this is pretty close but I figured out my issue which was something slightly different.
    – Jon Sakas
    Jan 22 '16 at 18:45

In addition to the answers already given, and based on the same logic (code has to be executed before body), another option is to use inline ampscript directly in the preheader, which of course opens up the option to place your dynamic logic in a code snippet and reference it via inline ampscript: %%=ContentBlockByKey('myPreheader')=%% can go into the Preheader section, and then do whatever you like in that code snippet, e.g.

/* myPreheader codeSnippet */

SET @test = "123preheader"
/* build your lookups here ... */

found this useful when using template-based emails, as the template often is the only place where you can access the area "before the body tag. A template change would of course be too global if you just want to set an individual preheader for one email.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.