Here i am trying to attach a dynamic pdf file which is getting generated after the order with the order Email. What i want is whenever customer order something after his order a pdf file should be generated which is getting generated successfully but i dont know how to attach it with the email.

I have edited success.phtml and have added this code at the end of it

$obj = $objectManager->get('Vendor\GeneratePDF\Controller\Page\MakePDF');
$orderid = $block->getOrderId();

Here generateReceipt is my controller function which generates the PDF file after the order success on success.phtml and it also saves my file into pub/media/Pdf directory but i have no idea how to attach this pdf with my Order Email to customer.

I have tried this extension. https://www.mageplaza.com/magento-2-email-attachments/?utm_source=mageplaza&utm_medium=mageplaza&utm_campaign=mageplaza-review&utm_content=Invoice

it attach a static file which we have uploaded from admin. I have tried to change one of its function in \Model\MailEvent.php

    protected $OrderId;
Public function getOrder($id)

private function getTacFile()

    $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
    $tacPath        = $this->dataHelper->getTacFile();
    $filePath       = $mediaDirectory->getAbsolutePath('Pdf' . $orderId.'.pdf');
    $content        = file_get_contents($filePath);
    $ext            = (string) substr($filePath, strrpos($filePath, '.') + 1);

    return [$content, $ext, self::MIME_TYPES[$ext]];

Above i have added a function which pass the orderId from success.phtml and then i tried to give path here failed. Is there anyway where i can attach my generated PDF with Order Email. Small Help will greately Appreciated. Thanks in Advance :)

| improve this question | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.