I have to add the email attachment. I have create a custom module
public function execute()
{
$post = $this->getRequest()->getPostValue();
if (!$post) {
$this->_redirect('/');
return;
}
$this->inlineTranslation->suspend();
try {
$recipientMail = $this->getRequest()->getPostValue('email');
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($post);
$error = false;
$sender = [
'name' => 'Test',
'email' => '[email protected]',
];
$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
->setTemplateOptions(
[
'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])
->setFrom($sender)
->addTo($recipientMail)
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
$this->messageManager->addSuccess(
__('Thanks for contacting us. We\'ll respond to you very soon.')
);
$this->_redirect('/');
return;
} catch (\Exception $e) {
$this->inlineTranslation->resume();
$this->messageManager->addError(
__('We can\'t process your request right now. Sorry, that\'s all we know.' . $e->getMessage())
);
$this->_redirect('/');
return;
}
}
}
Shashank Kumrawat
2,12824 silver badges61 bronze badges
-
Please add your code snippet here whatever you have tried ? and what problem you are getting.Shashank Kumrawat– Shashank Kumrawat2019年12月17日 10:20:46 +00:00Commented Dec 17, 2019 at 10:20
-
Send Email is working properly, I have to add the attachment file with the emailDivya– Divya2019年12月17日 10:33:50 +00:00Commented Dec 17, 2019 at 10:33
-
have you checked these URLs magento.stackexchange.com/questions/104044/… and dckap.com/blog/how-to-attach-a-pdf-file-to-emails-in-magento-2Shashank Kumrawat– Shashank Kumrawat2019年12月17日 10:38:04 +00:00Commented Dec 17, 2019 at 10:38
-
$attachment = $_transportBuilder->addAttachment($pdfData,$fileName); $bodyPart = new \Zend\Mime\Message(); $bodyPart->setParts(array($bodyMessage,$attachment)); $transport->getMessage()->setBody($bodyPart);Divya– Divya2019年12月17日 10:39:32 +00:00Commented Dec 17, 2019 at 10:39
-
I have tried this one, but not workingDivya– Divya2019年12月17日 10:39:39 +00:00Commented Dec 17, 2019 at 10:39
default