Custom email attachment file is not working in magento 2.3.
its working in Magento 2.2.X
Fatal error: Uncaught Error: Call to undefined method Magento\Framework\Mail\Message\Interceptor::createAttachment() in Mail/TransportBuilder.php
In magento 2.2.6 there is createAttachment method inside following path as same as magento 2.3
vendor\magento\zendframework1\library\Zend\Mail.php
but its giving method not defined
Please give any suggestion regarding issue
Best Answer
Try this way
Some of the functionalities in Magento 2.3.x is different from previous version.
The reason is that in most cases the 2.3.x framework uses Zend Framework 2 (ZF2) and almost totally refuses to applyZend Framework 1 (ZF1).
So, due to this, the previous method is deprecated and there is no direct method to do so.
As createAttachment() method is no more available, we will override Magento\Framework\Mail\Message and create a class which will implement Magento\Framework\Mail\MailMessageInterface.
[vendor_name] / [Module_name] /Mail
Message.php
After implementation of the Mail\Message class we need to extend the \Magento\Framework\Mail\Template\TransportBuilder class.
This class is used for building the \Magento\Framework\Mail\Transport class which is in turn used for email sending.
[Vendor_name] / [Module_name] /Model/Mail/Template
AddEmailAttachemnt.php
*Here value of Function Parameter*
**$file_content**
**$file_name**
this is name of file with extension like we have PDF file so name is **FileName.pdf**
**$file_type**
There are many File type for Different Files here are some File type list
Click Here to More File Type
**$encoding**
*here is Encoding type value of File on Internet if you are not pass this argument by default is 6-bit Encoding is apply. this value is depends on your file.*
Now you Have to add below Lines to your di.xml file which are call your Overwrite files.
[vendor_name] / [Module_name] / etc
di.xml
so now all file are place properly so now we will use send Email Attechment
Add this Code to send Email With Attechment
Now All code are Place at the Right place now run This Command
Now check your Receiver Email address attachment
Update in Magento [2.3.3]
Mangento 2.3.3 release introduces a new, immutable **EmailMessageInterface** that supports the sending of multi-part MIME-type content in email.
The Magento\Framework\Mail\Template\TransportBuilder and Magento\Newsletter\Model\Queue\TransportBuilder structures were refactored to use this new EmailMessageInterface instead of MessageInterface, which was previously used.
If you are a Magento extension developer and rely on \Magento\Email\Model\Transport::getMessage() or \Magento\Framework\Mail\TransportInterface::getMessage(), those methods will now return the new EmailMessageInterface.
Here add below Lines to your di.xml file which are call your Overwrite files.
[vendor_name] / [Module_name] / etc
di.xml
[Vendor_name] / [Module_name] /Model/Mail/Template
AddEmailAttachemnt.php
Add this Code to send Email With Attechment
Now All code are Place at the Right place now run This Command
Update in Magento [2.4]
Laminas is simply the next step in the evolution of the Zend Framework. Only the naming and governance of the framework has changed.
Anyone can still install all existing Zend Framework, Apigility, and Expressive packages. However, these versions will no longer be maintained by the community.Click here
Use code into Update in Magento [2.3.3]
Now check your Receiver Email address for attachment
I Hope This Helps You.