Last active
April 25, 2020 07:11
-
-
Save anzmage/41d1553388bffcf4c078c2e6cf35805d to your computer and use it in GitHub Desktop.
Magento 2 : Send Email use Object Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$variables = [ | |
data' => [ | |
'name'=> 'test', | |
'testvar'=> 'test34123123123' | |
] | |
]; | |
$sender = [ | |
'name'=>'somebody', | |
'email'=> '[email protected]' | |
]; | |
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | |
$storeManager = $objectManager->create('Magento\Store\Model\StoreManagerInterface'); | |
$transBuilder = $objectManager->create('Magento\Framework\Mail\Template\TransportBuilder'); | |
$transport = $transBuilder | |
->setTemplateIdentifier(19) // template id from Marketing -> EmailTemplates | |
->setTemplateOptions( | |
[ | |
'area' => Area::AREA_FRONTEND, | |
'store' => $storeManager->getStore()->getId() | |
] | |
) | |
->setTemplateVars($variables) | |
->setFrom($sender) | |
->addTo('[email protected]') | |
->getTransport(); | |
$transport->sendMessage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment