Skip to content

Commit

Permalink
Merge pull request #19 from iphoneps/feat/add-reply-to
Browse files Browse the repository at this point in the history
Add reply to to payload of transmissions api
  • Loading branch information
Henrik B Hansen authored Mar 2, 2022
2 parents 5fd200b + ef25b91 commit a645789
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Transport/SparkPostTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
'content' => [
'from' => $this->getFrom($message),
'subject' => $message->getSubject(),
'reply_to' => $this->getReplyTo($message),
'html' => $message->getHtmlBody(),
'text' => $message->getTextBody(),
'attachments' => $this->getAttachments($message),
Expand All @@ -94,19 +95,34 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
'X-SparkPost-Transmission-ID', $this->getTransmissionId($response)
);

return new SentMessage($message, $envelope);;
return new SentMessage($message, $envelope);
}

protected function getFrom(RawMessage $message): ?array
{
$from = $message->getFrom();

if (count($from)) {
return ['name' => $from[0]->getName(), 'email' => $from[0]->getAddress()];
}

return null;
}

protected function getReplyTo(RawMessage $message): ?string
{
$replyTo = $message->getHeaders()->getHeaderBody('reply-to') ?: [];

if (!count($replyTo)) {
return null;
}

$name = $replyTo[0]->getName();
$email = $replyTo[0]->getAddress();

return empty($email) ? $email : "{$name} <{$email}>";
}

protected function getRecipients(RawMessage $message): array
{
$recipients = [];
Expand Down Expand Up @@ -211,4 +227,4 @@ public function deleteSupression($email): JsonResponse
]);
}
}
}
}

0 comments on commit a645789

Please sign in to comment.