I want to send custom email programmatically without any template.
In magento 1, I used below script to do same thing.
$mail = Mage::getModel('core/email');
$mail->setToName('xxx');
$mail->settoemail('[email protected]');
$mail->setBody($html);
$mail->setSubject('Test email : '.$fieldss['o']);
$mail->setfromemail('[email protected]');
$mail->setType('html');// YOu can use Html or text as Mail format
$mail->setBodyHTML($html); // your content or message
try{
$mail->send();
}catch (Exception $e) {
echo $e->getMessage();exit;
}
Here, In magento 2 I used below code but it gives error.
$objectManager = $this->getObjectManager();
$transport = $objectManager->get('Magento\Framework\Mail\Template\TransportBuilder');
$transport->addTo('[email protected]', 'Hiren Shah');
//$transport->settoemail('[email protected]');
//$transport->setBody($html);
$transport->setSubject('Test email : '.$fieldss['o']);
$transport->setFrom('[email protected]');
$transport->setType('html');// YOu can use Html or text as Mail format
$transport->setBodyHTML($html); // your content or message
$transport->getTransport();
try {
$transport->sendMessage();
} catch (Exception $e) {
echo $e->getMessage();exit;
}
But this gives me error Call to undefined method Magento\Framework\Mail\Template\TransportBuilder\Interceptor::setSubject()
How to send custom email without template? Please give me code sample.