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

substitutionData per recipient #57

Closed
woodscreative opened this issue Mar 14, 2016 · 7 comments
Closed

substitutionData per recipient #57

woodscreative opened this issue Mar 14, 2016 · 7 comments
Milestone

Comments

@woodscreative
Copy link

Hi, it appears per recipient substitution data key is inconsistent consider the following:

$recipients = [
    [
        'name' => 'Foo',
        'email' => 'foo@example.com'
    ],
    [
        'name' => 'Bar',
        'email' => 'bar@example.com'
    ],
];
$mail[ 'substitutionData' ] = [
    'Company' => 'My Company Name - Works'
];
$mail 'subject' ] = 'Welcome to a Spark Post API Test';
$mail[ 'text' ] = 'Hi {{Name or 'Customer'}}, sent from {{Company}}';
$mail[ 'recipients' ] = [];
foreach ( $recipients as $recipient ) {
    $mail[ 'recipients' ][] = [
        'address' => [
          'name'    => $recipient[ 'name' ],
          'email'   => $recipient[ 'email' ]
        ],
        'substitutionData' => [
            'Name' => $recipient[ 'name' ] . ' - Nope'
        ],
        'substitution_data' => [
            'Name' => $recipient[ 'name' ] . '- Works'
        ]   
    ];
};
@richleland
Copy link
Contributor

Thanks for pointing this out @woodscreative. I think this is because we don't wrap the API that far down for recipients, rather just pass those through to the API. @beardyman I wonder if there is something we could do to translate keys from title case to snake case automagically?

@martinjbaker
Copy link

Thanks @woodscreative I was going around in circles and couldn't work out why the data wasn't coming through to the template.

@richleland
Copy link
Contributor

I'm going to leave this ticket open until we have the 2.x refactor out the door. We're planning on removing the parameterMapping, which is not only confusing to a lot of people, but causes exactly these types of problems.

@richleland richleland added this to the v2.0.0 milestone May 27, 2016
@suntrop
Copy link

suntrop commented May 31, 2016

Sorry to hook into this issue … but I am more confused than before. Does it mean it is impossible to personalize emails sent via API?
At least I can’t get the addresses and substitutionData work together.

Currently I have my recipients …
$address[] = array( 'address' => array( 'email' => "first@example.com", 'name' => "John" ) ); $address[] = array( 'address' => array( 'email' => "second@example.net", 'name' => "Mary" ) );

How do I implement the substitutionData? Do they have to be in the $address array or do they need to be an array of its own? Perhaps I missed some part of the docs, but I can't find a good example.

@suntrop
Copy link

suntrop commented May 31, 2016

Ok, now I got it. That was like Where's Waldo

It is not substitutionData but substitution**_d**ata

$address[] = array(
    'address' => array(
        'email' => 'first@example.com'
        ),
    'substitution_data'=> array(
                'name'=>'John',
            )
);

$address[] = array(
    'address' => array(
        'email' => 'second@example.net'
        ),
    'substitution_data'=> array(
                'name'=>'Mary',
            )
);

@richleland
Copy link
Contributor

Handled in 2.x branch via #121 and #122.

@richleland
Copy link
Contributor

2.0 has been released: https://packagist.org/packages/sparkpost/sparkpost

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

No branches or pull requests

4 participants