There are a couple of different approaches to this, which have been answered previously. However, the approach will vary depending on how your data is stored.
Previous answers refer to retrieving these values from a separate DE (other than your sendable/entry DE), which is not what you want — it appears that the values used for conditional evaluation will appear in your sendable/entry DE.
The easiest method would be to include the AMPscript block in a Content Block and invoke the Content Block, as maintaining code in the Sender Information form fields is fairly awkward.
Here's how I would approach this.
1. Create a Content Block
In Content Builder, create a Content Block with an 'Code Snippet' type (this is important, as even though you are not using this in your email, other blocks are wrapped in tables).
In your Content Block, add the following code:
%%[
var @fromName, @fromEmail
if AttributeValue('Brand') == 'Apple' then
set @fromName = 'Apple'
set @fromEmail = '[email protected]'
elseif AttributeValue('Brand') == 'Banana' then
set @fromName = 'Banana'
set @fromEmail = '[email protected]'
else /* fallback if neither evaluates to true */
set @fromName = 'Pear'
set @fromEmail = '[email protected]'
endif
]%%
Next I would recommend defining a Customer Key when you save the Sender Profile (which is easier to reference than defining the absolute path name to the Content Block). Enter a value like sender-profile
as your Customer Key value.
2. Add AMPscript to your Sender Information fields
In Email Studio, go to Admin > Sender Profiles and open the sender profile that you are using to send your email (or create a new one).
Then under Sender Information, select the 'Use the specified information' option and enter the following values in the fields:
From Name:
%%[ContentBlockByKey("sender-profile")]%%%%=v(@fromName)=%%
From Email:
%%[ContentBlockByKey("sender-profile")]%%%%=v(@fromEmail)=%%
If you used a value other than sender-profile
as your Customer Key value in the previous step, then you should update this here.
That's all that's required!