Hello,
I have a data object "product". I'm using the code below to send an email to the administrator when a new product is created. It will also send a different email when a product record was updated. Can someone till if I'm doing it in the correct way, or if there is a better way to set different email notifcations?
function onBeforeWrite() {
if(!$this->ID) {
$email = new Email();
$email->setTo('admin@domain.com');
$email->setSubject('New Record Created');
$email->setFrom('admin@domain.com');
$email->setBody("A new record was added");
$email->send();
}
if( $this->isChanged() && $this->ID) {
$email = new Email();
$email->setTo('admin@domain.comt');
$email->setSubject('Record details updated');
$email->setFrom('admin@domain.com');
$email->setBody("Details a record are updated");
$email->send();
}
parent::onBeforeWrite();
}
Thanks