I am trying to send mail on some condition. This is the code
public function sendMail() {
$email = oxNew(Email::class);
$email->setBody('this is body');
$email->setSubject('this is subject');
$email->setRecipient('[email protected]');
$email->send();
}
With this code above email is going correctly to mailtrap. But when i am trying to pass template in $email->setBody();
it doesn’t send email anymore and there comes an error in EXCEPTION_LOG.txt
[19 Aug 13:13:33.136970 2019] [exception] [type
OxidEsales\Eshop\Core\Exception\StandardException] [code 0] [file
/usr/www/users/asign/visana/vendor/oxid-esales/oxideshop-ce/source/Core/UtilsObject.php] [line
231] [message Message body empty]
This is what i do for sending template:
Module Metadata:
‘templates’ => array(
‘low_bonus_points.tpl’ => ‘views/custom/tpl/email/html/low_bonus_points.tpl’
),
Controller:
protected $_lowBonusPointsTemplate = "low_bonus_points.tpl";
public function sendMail() {
$email = oxNew(Email::class);
$smarty = $this->_getSmarty();`
$email->setBody($smarty->fetch($this->_lowBonusPointsTemplate));
$email->setSubject('this is subject');
$email->setRecipient('[email protected]');
$email->send();
}
protected function _getSmarty()
{
if ($this->_oSmarty === null) {
$this->_oSmarty = Registry::getUtilsView()->getSmarty();
}
//setting default view
$this->_oSmarty->assign("oEmailView", $this);
return $this->_oSmarty;
}