diff --git a/src/Adapter/Mailjet/MailjetAdapter.php b/src/Adapter/Mailjet/MailjetAdapter.php index 49b9a17..7b25c07 100644 --- a/src/Adapter/Mailjet/MailjetAdapter.php +++ b/src/Adapter/Mailjet/MailjetAdapter.php @@ -202,6 +202,18 @@ private function createMessage(MessageInterface $message) if ($message->hasVariables()) { $m['Variables'] = $message->getVariables(); } + + if ($message->hasAttachments()) { + $m['Attachments'] = []; + + foreach ($message->getAttachments() as $attachment) { + $m['Attachments'][] = [ + 'ContentType' => $attachment->getType(), + 'Filename' => $attachment->getName(), + 'Base64Content' => $attachment->getData(), + ]; + } + } } else { $m['HTMLPart'] = $message->getHtml(); $m['TextPart'] = $message->getText(); diff --git a/src/Adapter/SparkPost/SparkPostAdapter.php b/src/Adapter/SparkPost/SparkPostAdapter.php index e1973eb..3ba2bcf 100644 --- a/src/Adapter/SparkPost/SparkPostAdapter.php +++ b/src/Adapter/SparkPost/SparkPostAdapter.php @@ -99,6 +99,18 @@ public function sendMail(MessageInterface $message) if ($message->hasSubstitutionData()) { $payload['substitution_data'] = $message->getSubstitutionData(); } + + if ($message->hasAttachments()) { + $payload['attachments'] = []; + + foreach ($message->getAttachments() as $attachment) { + $payload['attachments'][] = [ + 'type' => $attachment->getType(), + 'name' => $attachment->getName(), + 'data' => $attachment->getData(), + ]; + } + } } else { $payload['content']['html'] = $message->getHtml(); $payload['content']['text'] = $message->getText(); diff --git a/src/Model/Attachment/Attachment.php b/src/Model/Attachment/Attachment.php index fd6e7ed..13a285f 100644 --- a/src/Model/Attachment/Attachment.php +++ b/src/Model/Attachment/Attachment.php @@ -12,12 +12,12 @@ class Attachment implements AttachmentInterface /** * @var string */ - protected $name = ''; + protected $name = 'Attachment'; /** * @var string */ - protected $type = ''; + protected $type = 'application/octet-stream'; /** * @var string @@ -33,11 +33,12 @@ public function getName() } /** + * Name of file. * @param string $name */ public function setName($name) { - $this->name = $name; + $this->name = (string)$name; } /** @@ -49,11 +50,12 @@ public function getType() } /** + * MIME type of file. * @param string $type */ public function setType($type) { - $this->type = $type; + $this->type = (string)$type; } /** @@ -65,10 +67,11 @@ public function getData() } /** + * Base64 encoded file content. * @param string $data */ public function setData($data) { - $this->data = $data; + $this->data = (string)$data; } }