Created
March 26, 2020 10:34
-
-
Save mklooss/971765646eefd861e437eda3845b2b88 to your computer and use it in GitHub Desktop.
Magento 2.3 Mail Transport add Attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$emailData = [ ... ]; | |
/* @var $transportBuilder \Magento\Framework\Mail\Template\TransportBuilder */ | |
/* @var $transport \Magento\Framework\Mail\Transport */ | |
$transport = $transportBuilder->getTransport(); | |
if (isset($emailData['attachments'])) | |
{ | |
$parts = $transport->getMessage()->getBody()->getParts(); | |
foreach ($emailData['attachments'] as $item) | |
{ | |
$attachment = new \Zend\Mime\Part($item['content']); | |
$attachment->type = $this->getContentTypeByName($item['name']); // define content type. eg. application/pdf | |
$attachment->filename = $item['name']; | |
$attachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT; | |
$attachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64; | |
$parts[] = $attachment; | |
} | |
$bodyPart = new \Zend\Mime\Message(); | |
$bodyPart->setParts($parts); | |
$transport->getMessage()->setBody($bodyPart); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment