Skip to content

Commit

Permalink
Allow get content type from files when rendering attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Oct 2, 2022
1 parent 507d84b commit fcb0729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ protected function renderAttachments() : string
$contents = (string) \file_get_contents($attachment);
$contents = \base64_encode($contents);
$part .= '--mixed-' . $this->getBoundary() . $crlf;
$part .= 'Content-Type: application/octet-stream; name="' . $filename . '"' . $crlf;
$part .= 'Content-Type: ' . $this->getContentType($attachment)
. '; name="' . $filename . '"' . $crlf;
$part .= 'Content-Disposition: attachment; filename="' . $filename . '"' . $crlf;
$part .= 'Content-Transfer-Encoding: base64' . $crlf . $crlf;
$part .= \chunk_split($contents) . $crlf;
Expand Down
14 changes: 12 additions & 2 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,19 @@ public function testAttachments() : void
self::assertEmpty($this->message->getAttachments());
$this->message->addAttachment(__FILE__);
self::assertSame([__FILE__], $this->message->getAttachments());
$this->message->addAttachment(__DIR__ . '/logo-circle.png');
self::assertSame([
__FILE__,
__DIR__ . '/logo-circle.png',
], $this->message->getAttachments());
$contents = $this->message->renderAttachments();
self::assertStringContainsString(
'text/x-php; name="MessageTest.php"',
$contents
);
self::assertStringContainsString(
'application/octet-stream; name="MessageTest.php"',
$this->message->renderAttachments()
'image/png; name="logo-circle.png"',
$contents
);
}

Expand Down

0 comments on commit fcb0729

Please sign in to comment.