diff --git a/SwiftMailer/MessageFormat/MessagePayloadV3.php b/SwiftMailer/MessageFormat/MessagePayloadV3.php index 6a90b0f..b65af3e 100644 --- a/SwiftMailer/MessageFormat/MessagePayloadV3.php +++ b/SwiftMailer/MessageFormat/MessagePayloadV3.php @@ -5,6 +5,7 @@ use \Swift_Mime_SimpleMessage; use \Swift_Attachment; use \Swift_MimePart; +use \Swift_Image; class MessagePayloadV3 extends BaseMessagePayload { @@ -41,23 +42,20 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { // Handle attachments foreach ($message->getChildren() as $child) { - if ($child instanceof Swift_Attachment) { - //Handle regular attachments - if ($child->getDisposition() === "attachment") { - $attachments[] = array( - 'Content-type' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'content' => base64_encode($child->getBody()) - ); - } - //Handle inline attachments - elseif ($child->getDisposition() === "inline") { - $inline_attachments[] = array( - 'Content-type' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'content' => base64_encode($child->getBody()) - ); - } + if (($child instanceof Swift_Attachment || $child instanceof Swift_Image) + && $child->getDisposition() === "inline" + ) { + $inline_attachments[] = array( + 'Content-type' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'content' => base64_encode($child->getBody()) + ); + } elseif ($child instanceof Swift_Attachment && $child->getDisposition() === "attachment") { + $attachments[] = array( + 'Content-type' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'content' => base64_encode($child->getBody()) + ); } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) { if ($child->getContentType() == "text/html") { $bodyHtml = $child->getBody(); diff --git a/SwiftMailer/MessageFormat/MessagePayloadV31.php b/SwiftMailer/MessageFormat/MessagePayloadV31.php index e25385d..5d08f52 100644 --- a/SwiftMailer/MessageFormat/MessagePayloadV31.php +++ b/SwiftMailer/MessageFormat/MessagePayloadV31.php @@ -4,6 +4,7 @@ use \Swift_Mime_SimpleMessage; use \Swift_Attachment; +use \Swift_Image; use \Swift_MimePart; class MessagePayloadV31 extends BaseMessagePayload { @@ -72,7 +73,16 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { // Handle attachments foreach ($message->getChildren() as $child) { - if ($child instanceof Swift_Attachment) { + if (($child instanceof Swift_Attachment || $child instanceof Swift_Image) + && $child->getDisposition() === "inline" + ) { + $inline_attachments[] = array( + 'ContentType' => $child->getContentType(), + 'Filename' => $child->getFilename(), + 'ContentID' => $child->getId(), + 'Base64Content' => base64_encode($child->getBody()) + ); + } elseif ($child instanceof Swift_Attachment) { //Handle regular attachments if ($child->getDisposition() === "attachment") { $attachments[] = array( @@ -82,14 +92,6 @@ public function getMailjetMessage(Swift_Mime_SimpleMessage $message) { ); } //Handle inline attachments - elseif ($child->getDisposition() === "inline") { - $inline_attachments[] = array( - 'ContentType' => $child->getContentType(), - 'Filename' => $child->getFilename(), - 'ContentID' => $child->getId(), - 'Base64Content' => base64_encode($child->getBody()) - ); - } } elseif ($child instanceof Swift_MimePart && $this->supportsContentType($child->getContentType())) { if ($child->getContentType() == "text/html") { $bodyHtml = $child->getBody(); diff --git a/Tests/SwiftMailer/MailjetTransportv31Test.php b/Tests/SwiftMailer/MailjetTransportv31Test.php index 65293cf..6e6ccb9 100644 --- a/Tests/SwiftMailer/MailjetTransportv31Test.php +++ b/Tests/SwiftMailer/MailjetTransportv31Test.php @@ -209,6 +209,24 @@ public function testMessage() { $this->assertMessageSendable($message); } + public function testInlineImage() { + $transport = $this->createTransport(); + $message = new \Swift_Message('Test Subject', '

Foo bar

', 'text/html'); + $inline_image = new \Swift_Image($this->createPngContent(), 'filename.png', 'image/png'); + $message->attach($inline_image); + $message + ->addTo('to@example.com', 'To Name') + ->addFrom('from@example.com', 'From Name') + ; + $mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0]; + + $transport->send($message); + + $this->assertMailjetMessageContainsInlineAttachment('image/png', 'filename.png', $this->createPngContent(), $mailjetMessage); + + $this->assertMessageSendable($message); + } + public function testBulkSendMessages() { $transport = $this->createTransport(); diff --git a/composer.json b/composer.json index 050bf91..7541f88 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ }, "require-dev": { "phpunit/phpunit": "^5.7", - "symfony/config": ">=2.0|~3.0" + "symfony/config": "^3.4" }, "license": "MIT", "authors": [