I have to add the email attachment. I have create a custom module

public function execute()
    $post = $this->getRequest()->getPostValue();
    if (!$post) {

    try {
        $recipientMail = $this->getRequest()->getPostValue('email');

        $postObject = new \Magento\Framework\DataObject();

        $error = false;

        $sender = [
          'name' => 'Test',
          'email' => 'test@gmail.com',

       $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

       $transport = $this->_transportBuilder
        ->setTemplateIdentifier('send_email_email_template') // this code we have mentioned in the email_templates.xml
                'area' => \Magento\Framework\App\Area::AREA_FRONTEND, // this is using frontend area to get the template file
                'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
        ->setTemplateVars(['data' => $postObject])

        __('Thanks for contacting us. We\'ll respond to you very soon.')
   } catch (\Exception $e) {
        __('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())


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.