How to send variables like {contactfield=id} in MAUTIC email campaign?

1.1k views Asked by At

I want to send {contactfield=id} (one of the variable of the mautic) into custom headers for a mail that is to be used for a campaign. I am not sure of the right way to send it. I am keeping this variable into custom headers under Channels > Emails and selecting a particular email's advanced settings and into custom headers. This sets the id value of the first contact in the contact list of the segment selected for the campaign into all the remaining contacts. I want to get the dynamic value of each contact's id respectively. How can I get this appropriate result? Thanks in advance.

2

There are 2 answers

3
Jordan Ryan On

Last time I checked, not all of the fields in the Email builder can contain tokens. I remember that the Body and Subject allow it, but there were some other fields that did not allow it.

You seem to be getting the correct token, so if it's not returning in the header based on your testing, that field may not get parsed for tokenization on processing.

0
Mayank Tiwari On

As pointed out by Jordan Ryan, not all tokens are available under email, however the email object can be tapped by creating a custom plugin.

https://developer.mautic.org/#extending-emails check out this section, it may help.

The second example on code block shows that you can place your custom placeholder and then replace it programmatically.

/**
 * Search and replace tokens with content
 *
 * @param EmailSendEvent $event
 */
public function onEmailGenerate(EmailSendEvent $event)
{
    // Get content
    $content = $event->getContent();

    // Search and replace tokens
    $content = str_replace('{hello}', 'world!', $content);

    // Set updated content
    $event->setContent($content);
}