diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 5e12a30ba0e..1f8c9cf3225 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -847,12 +847,36 @@ class Notify $mimefilename_list[] = $ref.".pdf"; } - $message = ''; - $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n"; - $message .= "\n"; - $message .= $mesg; + // if an e-mail template is configured for this notification code (for instance + // 'SHIPPING_VALIDATE_TEMPLATE'), we fetch this template by its label. Otherwise, a default message + // content will be sent. + $mailTemplateLabel = isset($conf->global->{$notifcode.'_TEMPLATE'}) ? $conf->global->{$notifcode.'_TEMPLATE'} : ''; + $emailTemplate = null; + if (!empty($mailTemplateLabel)) { + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($this->db); + $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type.'_send', $user, $outputlangs, 0, 1, $labeltouse); + } + if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) { + // Set output language + $outputlangs = $langs; + if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) { + $outputlangs = new Translate('', $conf); + $outputlangs->setDefaultLang($obj->default_lang); + $outputlangs->loadLangs(array('main', 'other')); + } + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $subject = make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs); + $message = make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs); + } else { + $message = ''; + $message .= $langs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name)."\n"; + $message .= "\n"; + $message .= $mesg; - $message = nl2br($message); + $message = nl2br($message); + } // Replace keyword __SUPERVISOREMAIL__ if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) {