FIX 16.0 - the e-mail templates configured in the notification module are not used if the recipient is a fixed e-mail address (#29407)

This commit is contained in:
Florian Mortgat 2024-04-20 23:44:26 +02:00 committed by GitHub
parent dc988f7e37
commit 54caae51e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)) {