Skip to content

Commit 3a178d9

Browse files
committed
Store the SparkPost transmission ID in the header X-SparkPost-Transmission-ID after the message has been sent
1 parent d3c9668 commit 3a178d9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Illuminate/Mail/Transport/SparkPostTransport.php

+16-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
5454

5555
$message->setBcc([]);
5656

57-
$this->client->post('https://api.sparkpost.com/api/v1/transmissions', [
57+
$response = $this->client->post('https://api.sparkpost.com/api/v1/transmissions', [
5858
'headers' => [
5959
'Authorization' => $this->key,
6060
],
@@ -66,6 +66,8 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null)
6666
], $this->options),
6767
]);
6868

69+
$message->getHeaders()->addTextHeader('X-SparkPost-Transmission-ID', $this->getTransmissionId($response));
70+
6971
$this->sendPerformed($message);
7072

7173
return $this->numberOfRecipients($message);
@@ -98,6 +100,19 @@ protected function getRecipients(Swift_Mime_Message $message)
98100
return $recipients;
99101
}
100102

103+
/**
104+
* Get the transmission ID from the response.
105+
*
106+
* @param \GuzzleHttp\Psr7\Response $response
107+
* @return string
108+
*/
109+
protected function getTransmissionId($response)
110+
{
111+
$result = json_decode($response->getBody()->getContents());
112+
113+
return object_get($result, 'results.id');
114+
}
115+
101116
/**
102117
* Get the API key being used by the transport.
103118
*

0 commit comments

Comments
 (0)