Skip to content

Instantly share code, notes, and snippets.

@anzmage
Last active April 25, 2020 07:11
Show Gist options
  • Save anzmage/41d1553388bffcf4c078c2e6cf35805d to your computer and use it in GitHub Desktop.
Save anzmage/41d1553388bffcf4c078c2e6cf35805d to your computer and use it in GitHub Desktop.
Magento 2 : Send Email use Object Manager
$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