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

Support for subaccounts #24

Closed
wittsparks opened this issue Oct 7, 2022 · 2 comments
Closed

Support for subaccounts #24

wittsparks opened this issue Oct 7, 2022 · 2 comments

Comments

@wittsparks
Copy link

I'm currently using a fork of this package to add support for subaccounts. Here is my change to src/Transport/SparkPostTransport.php:

 public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
    {
        $recipients = $this->getRecipients($message);

        $headers = ['Authorization' => $this->key];
        $subaccount_id = $message->getHeaders()->get('subaccount_id');
        if ($subaccount_id) {
            $headers['X-MSYS-SUBACCOUNT'] = $subaccount_id->getValue();
        }

        $response = $this->client->request('POST', $this->getEndpoint() . '/transmissions', [
            'headers' => $headers,
            'json' => array_merge([
...

To add a subaccount to a message, add it to the message headers in a Mailable:

$this->withSymfonyMessage(function ($message) use ($subaccount_id) {
              $headers = $message->getHeaders();
              $headers->addTextHeader('subaccount_id', $subaccount_id);
 });

I'd be happy to submit this as a PR.

@eldor
Copy link
Contributor

eldor commented Oct 10, 2022

Hi @wittsparks seems ok, create a PR and we will look into it.

@eldor
Copy link
Contributor

eldor commented Oct 11, 2022

Thanks for the PR, its merged

@eldor eldor closed this as completed Oct 11, 2022
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

2 participants