Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle X-MJ-Vars as json string #6

Merged
merged 2 commits into from
Oct 27, 2017
Merged

Handle X-MJ-Vars as json string #6

merged 2 commits into from
Oct 27, 2017

Conversation

Nightbr
Copy link
Member

@Nightbr Nightbr commented Oct 26, 2017

See issue #5

In order to remove SwiftMailer error/warning when you try to pass an array of variables to X-MJ-Vars, I propose to json_encode when we set the header and in our BaseMessagePayload we json_decode in order to create the payload for the API properly.

Only tested against API v3.1 on my side.

Code Example:

    /**
     * Configure specific headers for message
     * @method configureHeaders
     * @param  \Swift_Message    $message
     * @return \Swift_Message
     */
    protected function configureHeaders(\Swift_Message $message, $templateId, array $vars)
    {
        //Configure Headers
        $headers = $message->getHeaders();

        $headers->addTextHeader('X-MJ-TemplateID', $templateId);
        $headers->addTextHeader('X-MJ-TemplateLanguage', true);
        $headers->addTextHeader('X-MJ-Vars', json_encode($vars));

        return $message;
    }

@Nightbr Nightbr requested a review from latanasov October 26, 2017 16:35
Copy link
Contributor

@latanasov latanasov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good to me.

@Nightbr Nightbr merged commit bd1c115 into master Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants