vemcogroup / laravel-sparkpost-driver

SparkPost driver to use with Laravel
MIT License
40 stars 16 forks source link

Support for subaccounts #24

Closed wittsparks closed 1 year ago

wittsparks commented 1 year ago

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 commented 1 year ago

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

eldor commented 1 year ago

Thanks for the PR, its merged