Magento – How to Add Attachment with email magento 2.3

attachmentemailmagento2.3

Can anyone help us on Add Attachment with email Magento 2.3? We have tried but face the same issue like this.

Fatal error: Uncaught Error: Call to undefined method Magento\Framework\Mail\Message\Interceptor::createAttachment() in Mail/TransportBuilder.php

Thank you in advance.

Best Answer

https://extait.com/blog/how-to-send-email-with-attachment-in-magento-2-3/

As from above link add encoding concept..

 public function setBodyAttachment($content, $fileName, $fileType)
{
    $attachmentPart = $this->partFactory->create();
    $attachmentPart->setContent($content)
        ->setType($fileType)
        ->setFileName($fileName)
        ->setEncoding(Mime::ENCODING_BASE64) /*Add this*/
        ->setDisposition(Mime::DISPOSITION_ATTACHMENT);

    $this->parts[] = $attachmentPart;

    return $this;
}