joomlagerman / joomla

The J!German translation team provides German translation for Joomla!
https://www.jgerman.de
GNU General Public License v2.0
25 stars 46 forks source link

[4.0] Converting several mails to mail templates #1079

Closed jgerman-bot closed 4 years ago

jgerman-bot commented 4 years ago

New language relevant PR in upstream repo: https://github.com/joomla/joomla-cms/pull/28722 Here are the upstream changes:

diff --git a/administrator/components/com_admin/sql/updates/mysql/4.0.0-2020-04-16.sql b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2020-04-16.sql
new file mode 100644
index 000000000000..6507312fcfdd
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/mysql/4.0.0-2020-04-16.sql
@@ -0,0 +1,8 @@
+INSERT INTO `#__mail_templates` (`template_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES
+('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
+('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
+('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
+('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
+('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');
diff --git a/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2020-04-16.sql b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2020-04-16.sql
new file mode 100644
index 000000000000..339469fb3600
--- /dev/null
+++ b/administrator/components/com_admin/sql/updates/postgresql/4.0.0-2020-04-16.sql
@@ -0,0 +1,8 @@
+INSERT INTO "#__mail_templates" ("template_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES
+('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
+('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
+('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
+('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
+('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');
diff --git a/administrator/components/com_mails/src/View/Template/HtmlView.php b/administrator/components/com_mails/src/View/Template/HtmlView.php
index 11eb214c0c90..bf10e1ad4639 100644
--- a/administrator/components/com_mails/src/View/Template/HtmlView.php
+++ b/administrator/components/com_mails/src/View/Template/HtmlView.php
@@ -87,6 +87,7 @@ public function display($tpl = null)
        $fields = array('subject', 'body', 'htmlbody');
        $this->templateData = array();
        $language = Factory::getLanguage();
+       $language->load($component, JPATH_SITE, $this->item->language, true);
        $language->load($component, JPATH_ADMINISTRATOR, $this->item->language, true);

        foreach ($fields as $field)
diff --git a/administrator/components/com_mails/tmpl/template/edit.php b/administrator/components/com_mails/tmpl/template/edit.php
index 9b4fc7029ddf..8f1191922900 100644
--- a/administrator/components/com_mails/tmpl/template/edit.php
+++ b/administrator/components/com_mails/tmpl/template/edit.php
@@ -28,6 +28,7 @@

 $input = $app->input;
 list($component, $sub_id) = explode('.', $this->master->template_id, 2);
+$sub_id = str_replace('.', '_', $sub_id);

 $doc->addScriptOptions('com_mails', ['templateData' => $this->templateData]);

diff --git a/administrator/components/com_mails/tmpl/templates/default.php b/administrator/components/com_mails/tmpl/templates/default.php
index 83ec3d06fbf0..2e8f3867e161 100644
--- a/administrator/components/com_mails/tmpl/templates/default.php
+++ b/administrator/components/com_mails/tmpl/templates/default.php
@@ -59,6 +59,7 @@
                        <tbody>
                        <?php foreach ($this->items as $i => $item) :
                            list($component, $sub_id) = explode('.', $item->template_id, 2);
+                           $sub_id = str_replace('.', '_', $sub_id);
                            ?>
                            <tr class="row<?php echo $i % 2; ?>">
                                <td class="break-word">
diff --git a/administrator/components/com_users/src/Model/MailModel.php b/administrator/components/com_users/src/Model/MailModel.php
index 9c6ac54e52f8..53cbdf85c412 100644
--- a/administrator/components/com_users/src/Model/MailModel.php
+++ b/administrator/components/com_users/src/Model/MailModel.php
@@ -19,6 +19,7 @@
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
 use Joomla\CMS\Mail\Exception\MailDisabledException;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\MVC\Model\AdminModel;
 use Joomla\Database\ParameterType;
 use PHPMailer\PHPMailer\Exception as phpMailerException;
@@ -97,11 +98,12 @@ protected function preprocessForm(Form $form, $data, $group = 'user')
     */
    public function send()
    {
-       $app    = Factory::getApplication();
-       $data   = $app->input->post->get('jform', array(), 'array');
-       $user   = Factory::getUser();
-       $access = new Access;
-       $db     = $this->getDbo();
+       $app      = Factory::getApplication();
+       $data     = $app->input->post->get('jform', array(), 'array');
+       $user     = Factory::getUser();
+       $access   = new Access;
+       $db       = $this->getDbo();
+       $language = Factory::getLanguage();

        $mode         = array_key_exists('mode', $data) ? (int) $data['mode'] : 0;
        $subject      = array_key_exists('subject', $data) ? $data['subject'] : '';
@@ -176,30 +178,40 @@ public function send()
        }

        // Get the Mailer
-       $mailer = Factory::getMailer();
+       $mailer = new MailTemplate('com_users.massmail.mail', $language->getTag());
        $params = ComponentHelper::getParams('com_users');

        try
        {
            // Build email message format.
-           $mailer->setSender(array($app->get('mailfrom'), $app->get('fromname')));
-           $mailer->setSubject($params->get('mailSubjectPrefix') . stripslashes($subject));
-           $mailer->setBody($message_body . $params->get('mailBodySuffix'));
-           $mailer->IsHtml($mode);
+           $data = [
+               'subject' => stripslashes($subject),
+               'body' => $message_body,
+               'subjectprefix' => $params->get('mailSubjectPrefix', ''),
+               'bodysuffix' => $params->get('mailBodySuffix', '')
+           ];
+           $mailer->addTemplateData($data);

            // Add recipients
            if ($bcc)
            {
-               $mailer->addBcc($rows);
+               foreach ($rows as $row)
+               {
+                   $mailer->addRecipient($row, null, 'bcc');
+               }
+
                $mailer->addRecipient($app->get('mailfrom'));
            }
            else
            {
-               $mailer->addRecipient($rows);
+               foreach ($rows as $row)
+               {
+                   $mailer->addRecipient($row);
+               }
            }

            // Send the Mail
-           $rs = $mailer->Send();
+           $rs = $mailer->send();
        }
        catch (MailDisabledException | phpMailerException $exception)
        {
diff --git a/administrator/language/en-GB/com_contact.ini b/administrator/language/en-GB/com_contact.ini
index 3bee43422d7b..79a6082aed4e 100644
--- a/administrator/language/en-GB/com_contact.ini
+++ b/administrator/language/en-GB/com_contact.ini
@@ -141,6 +141,10 @@ COM_CONTACT_HEADING_ASSOCIATION="Association"
 COM_CONTACT_ICONS_SETTINGS="Icons"
 COM_CONTACT_ID_LABEL="ID"
 COM_CONTACT_MAIL_FIELDSET_LABEL="Mail Options"
+COM_CONTACT_MAIL_MAIL_COPY_DESC="This mail is sent to the submitter of a mail with the contact form if option \"Send Copy to Submitter\" is switched on in the form settings."
+COM_CONTACT_MAIL_MAIL_COPY_TITLE="Contacts: Contact Form Mail Copy"
+COM_CONTACT_MAIL_MAIL_DESC="This mail is sent with the contact form."
+COM_CONTACT_MAIL_MAIL_TITLE="Contacts: Contact Form Mail"
 COM_CONTACT_MANAGER_CONTACTS="Contacts"
 COM_CONTACT_MANAGER_CONTACT_EDIT="Contacts: Edit"
 COM_CONTACT_MANAGER_CONTACT_NEW="Contacts: New"
diff --git a/administrator/language/en-GB/com_users.ini b/administrator/language/en-GB/com_users.ini
index de0492208591..694c58d3a015 100644
--- a/administrator/language/en-GB/com_users.ini
+++ b/administrator/language/en-GB/com_users.ini
@@ -178,15 +178,23 @@ COM_USERS_MAIL_FIELD_SEND_AS_BLIND_CARBON_COPY_LABEL="Recipients as BCC"
 COM_USERS_MAIL_FIELD_SEND_IN_HTML_MODE_LABEL="Send in HTML Mode"
 COM_USERS_MAIL_FIELD_SUBJECT_LABEL="Subject"
 COM_USERS_MAIL_FIELD_VALUE_ALL_USERS_GROUPS="All Users Groups"
+COM_USERS_MAIL_MASSMAIL_MAIL_DESC="This mail is sent with the \"Mass Mail Users\" form in backend."
+COM_USERS_MAIL_MASSMAIL_MAIL_TITLE="Users: Mass Mail Users"
 COM_USERS_MAIL_NO_USERS_COULD_BE_FOUND_IN_THIS_GROUP="No users could be found in this group."
 COM_USERS_MAIL_ONLY_YOU_COULD_BE_FOUND_IN_THIS_GROUP="You are the only user in this group."
+COM_USERS_MAIL_PASSWORD_RESET_DESC="This mail is sent to a user by using the \"Forgot your password?\" link e.g. in a login form."
+COM_USERS_MAIL_PASSWORD_RESET_TITLE="Users: Password Reset"
 COM_USERS_MAIL_PLEASE_FILL_IN_THE_FORM_CORRECTLY="Please fill in the form correctly."
 COM_USERS_MAIL_PLEASE_FILL_IN_THE_MESSAGE="Please enter a message"
 COM_USERS_MAIL_PLEASE_FILL_IN_THE_SUBJECT="Please enter a subject"
 COM_USERS_MAIL_PLEASE_SELECT_A_GROUP="Please select a Group"
+COM_USERS_MAIL_REMINDER_DESC="This mail is sent to a user when by the \"Forgot your username?\" link e.g. in a login form."
+COM_USERS_MAIL_REMINDER_TITLE="Users: Username Reminder"
 COM_USERS_MAIL_THE_MAIL_COULD_NOT_BE_SENT="The mail could not be sent."
 COM_USERS_MASS_MAIL="Mass Mail Users"
 COM_USERS_MASS_MAIL_DESC="Mass Mail options."
+COM_USERS_MASSMAIL_MAIL_BODY="{BODY} {BODYSUFFIX}"
+COM_USERS_MASSMAIL_MAIL_SUBJECT="{SUBJECTPREFIX} {SUBJECT}"
 COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N="Password does not have enough digits. At least %s digits are required."
 COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N_1="Password does not have enough digits. At least 1 digit is required."
 COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N="Password does not have enough lower case characters. At least %s lower case characters are required."
diff --git a/administrator/language/en-GB/plg_system_updatenotification.ini b/administrator/language/en-GB/plg_system_updatenotification.ini
index 73f42c83c9e4..4dd1bd551476 100644
--- a/administrator/language/en-GB/plg_system_updatenotification.ini
+++ b/administrator/language/en-GB/plg_system_updatenotification.ini
@@ -6,19 +6,13 @@
 PLG_SYSTEM_UPDATENOTIFICATION="System - Joomla! Update Notification"
 PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_LBL="Super User Emails"
 PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_DESC="A comma separated list of the email addresses which will receive the update notification emails. The addresses in the list MUST belong to existing users of your site who have the Super User privilege. If none of the listed emails belongs to Super Users, or if it's left blank, all Super Users of this site will receive the update notification email."
-; You can use the following merge codes:
-; [NEWVERSION]     New Joomla! version, e.g. 1.2.3
-; [CURVERSION]     Currently installed Joomla! version, e.g. 1.2.0
-; [SITENAME]       Site name, as set in Global Configuration.
-; [URL]                URL of the site's frontend page.
-; [LINK]           Update URL (link to com_joomlaupdate, will request login if the Super User isn't already logged in).
-; [RELEASENEWS]        URL to the release news on joomla.org
-; \n               Newline character. Use it to start a new line in the email.
-PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT="Joomla! Update available for [SITENAME] – [URL]"
-PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY="This email IS NOT sent by Joomla.org. It is sent automatically by your own site,\n[SITENAME] - [URL] \n\n================================================================================\nUPDATE INFORMATION\n================================================================================\n\nYour site has discovered that there is an updated version of Joomla! available for download.\n\nJoomla! version currently installed:        [CURVERSION]\nJoomla! version available for installation: [NEWVERSION]\n\nThis email is sent to you by your site to remind you of this fact.\nThe Joomla! project will never contact you directly about available updates of Joomla! on your site.\n\n================================================================================\nUPDATE INSTRUCTIONS\n================================================================================\n\nTo install the update on [SITENAME] please select the following link. (If the URL is not a link, copy & paste it to your browser).\n\nUpdate link: [LINK]\n\nRelease News can be found here: [RELEASENEWS]\n\n================================================================================\nWHY AM I RECEIVING THIS EMAIL?\n================================================================================\n\nThis email has been automatically sent by a plugin provided by Joomla!, the software which powers your site.\nThis plugin looks for updated versions of Joomla! and sends an email notification to its administrators.\nYou will receive several similar emails from your site until you either update the software or disable these emails.\n\nTo disable these emails, please unpublish the 'System - Joomla! Update Notification' plugin in the Plugin Manager on your site.\n\nIf you do not understand what Joomla! is and what you need to do please do not contact the Joomla! project.\nThey are NOT sending you this email and they cannot help you. Instead, please contact the person who built or manages your site.\n\nIf you are the person who built or manages your website, please note that this plugin may have been activated automatically when you installed or updated Joomla! on your site.\n\n================================================================================\nWHO SENT ME THIS EMAIL?\n================================================================================\n\nThis email is sent to you by your own site, [SITENAME]"
+PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT="Joomla! Update available for {SITENAME} – {URL}"
+PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY="This email IS NOT sent by Joomla.org. It is sent automatically by your own site,\n{SITENAME} - {URL} \n\n================================================================================\nUPDATE INFORMATION\n================================================================================\n\nYour site has discovered that there is an updated version of Joomla! available for download.\n\nJoomla! version currently installed:        {CURVERSION}\nJoomla! version available for installation: {NEWVERSION}\n\nThis email is sent to you by your site to remind you of this fact.\nThe Joomla! project will never contact you directly about available updates of Joomla! on your site.\n\n================================================================================\nUPDATE INSTRUCTIONS\n================================================================================\n\nTo install the update on {SITENAME} please select the following link. (If the URL is not a link, copy & paste it to your browser).\n\nUpdate link: {LINK}\n\nRelease News can be found here: {RELEASENEWS}\n\n================================================================================\nWHY AM I RECEIVING THIS EMAIL?\n================================================================================\n\nThis email has been automatically sent by a plugin provided by Joomla!, the software which powers your site.\nThis plugin looks for updated versions of Joomla! and sends an email notification to its administrators.\nYou will receive several similar emails from your site until you either update the software or disable these emails.\n\nTo disable these emails, please unpublish the 'System - Joomla! Update Notification' plugin in the Plugin Manager on your site.\n\nIf you do not understand what Joomla! is and what you need to do please do not contact the Joomla! project.\nThey are NOT sending you this email and they cannot help you. Instead, please contact the person who built or manages your site.\n\nIf you are the person who built or manages your website, please note that this plugin may have been activated automatically when you installed or updated Joomla! on your site.\n\n================================================================================\nWHO SENT ME THIS EMAIL?\n================================================================================\n\nThis email is sent to you by your own site, {SITENAME}"
 PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_LBL="Email Language"
 PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_DESC="Select a language for the update notification emails. Set to Auto to send them in the site language at the time."
 PLG_SYSTEM_UPDATENOTIFICATION_LANGUAGE_OVERRIDE_NONE="Auto"
+PLG_SYSTEM_UPDATENOTIFICATION_MAIL_MAIL_DESC="This mail is sent to the site administrator when the \"Joomla! Update Notification\" system plugin has detected an available update."
+PLG_SYSTEM_UPDATENOTIFICATION_MAIL_MAIL_TITLE="Joomla: Update Notification"
 PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME="The Joomla! Update Notification will not run in this configuration"
 PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_BODY="In your Installer Configuration you have set the Option Update Cache (in Hours) to 0 this means that Joomla is not caching the Update. This means an email should be sent on every page visit but this is not possible. Please increase the value (6 is default) or confirm that the Joomla! Update Notification will never send you mails."
 PLG_SYSTEM_UPDATENOTIFICATION_POSTINSTALL_UPDATECACHETIME_ACTION="Set it back to the default setting (6 Hours)"
diff --git a/administrator/language/en-GB/plg_user_joomla.ini b/administrator/language/en-GB/plg_user_joomla.ini
index 318b912c62b4..2db2e81187b1 100644
--- a/administrator/language/en-GB/plg_user_joomla.ini
+++ b/administrator/language/en-GB/plg_user_joomla.ini
@@ -8,7 +8,9 @@ PLG_USER_JOOMLA_FIELD_AUTOREGISTER_LABEL="Auto-create Users"
 PLG_USER_JOOMLA_FIELD_FORCELOGOUT_LABEL="Force Logout for all Sessions?"
 PLG_USER_JOOMLA_FIELD_MAILTOUSER_LABEL="Notification Mail to User"
 PLG_USER_JOOMLA_FIELD_STRONG_PASSWORDS_LABEL="Strong Passwords"
-PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY="Hello %s,\n\n\nYou have been added as a User to %s by an Administrator.\n\nThis email has your username and password to log in to %s\n\nUsername: %s\nPassword: %s\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only."
+PLG_USER_JOOMLA_MAIL_MAIL_DESC="This mail is sent to a new user who has just been created in backend."
+PLG_USER_JOOMLA_MAIL_MAIL_TITLE="Users: New User"
+PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY="Hello {NAME},\n\n\nYou have been added as a User to {SITENAME} by an Administrator.\n\nThis email has your username and password to log in to {URL}\n\nUsername: {USERNAME}\nPassword: {PASSWORD}\n\n\nPlease do not respond to this message as it is automatically generated and is for information purposes only."
 PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT="New User Details"
 PLG_USER_JOOMLA_POSTINSTALL_STRONGPW_BTN="Enable Strong Password Encryption"
 PLG_USER_JOOMLA_POSTINSTALL_STRONGPW_TEXT="As a security feature, Joomla allows you to switch to strong password encryption.<br>To turn strong passwords on select the button below. Alternatively you can edit the User - Joomla plugin and change the strong password setting to On.<br>Before enabling you should verify that all third party registration/login, user management or bridge extensions installed on your site support this strong password encryption."
diff --git a/api/components/com_contact/src/Controller/ContactController.php b/api/components/com_contact/src/Controller/ContactController.php
index a669b9e0572d..769616606176 100644
--- a/api/components/com_contact/src/Controller/ContactController.php
+++ b/api/components/com_contact/src/Controller/ContactController.php
@@ -17,6 +17,7 @@
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
 use Joomla\CMS\Mail\Exception\MailDisabledException;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\MVC\Controller\Exception\SendEmail;
 use Joomla\CMS\String\PunycodeHelper;
 use Joomla\CMS\Uri\Uri;
@@ -204,69 +205,60 @@ private function _sendEmail($data, $contact, $copy_email_activated)
    {
        $app = $this->app;

+       Factory::getLanguage()->load('com_contact', JPATH_SITE, $app->getLanguage()->getTag(), true);
+
        if ($contact->email_to == '' && $contact->user_id != 0)
        {
            $contact_user      = User::getInstance($contact->user_id);
            $contact->email_to = $contact_user->get('email');
        }

-       $mailfrom = $app->get('mailfrom');
-       $fromname = $app->get('fromname');
-       $sitename = $app->get('sitename');
-
-       $name    = $data['contact_name'];
-       $email   = PunycodeHelper::emailToPunycode($data['contact_email']);
-       $subject = $data['contact_subject'];
-       $body    = $data['contact_message'];
-
-       // Prepare email body
-       $prefix = Text::sprintf('COM_CONTACT_ENQUIRY_TEXT', Uri::base());
-       $body   = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body);
+       $templateData = [
+           'sitename' => $app->get('sitename'),
+           'name'     => $data['contact_name'],
+           'contactname' => $contact->name,
+           'email'    => PunycodeHelper::emailToPunycode($data['contact_email']),
+           'subject'  => $data['contact_subject'],
+           'body'     => stripslashes($data['contact_message']),
+           'url'      => Uri::base(),
+           'customfields' => ''
+       ];

        // Load the custom fields
        if (!empty($data['com_fields']) && $fields = FieldsHelper::getFields('com_contact.mail', $contact, true, $data['com_fields']))
        {
            $output = FieldsHelper::render(
                'com_contact.mail',
-               'fields.render', [
+               'fields.render',
+               array(
                    'context' => 'com_contact.mail',
                    'item'    => $contact,
                    'fields'  => $fields,
-               ]
+               )
            );

            if ($output)
            {
-               $body .= "\r\n\r\n" . $output;
+               $templateData['customfields'] = $output;
            }
        }

        try
        {
-           $mail = Factory::getMailer();
-           $mail->addRecipient($contact->email_to);
-           $mail->addReplyTo($email, $name);
-           $mail->setSender([$mailfrom, $fromname]);
-           $mail->setSubject($sitename . ': ' . $subject);
-           $mail->setBody($body);
-           $sent = $mail->Send();
+           $mailer = new MailTemplate('com_contact.mail', $app->getLanguage()->getTag());
+           $mailer->addRecipient($contact->email_to);
+           $mailer->setReplyTo($templateData['email'], $templateData['name']);
+           $mailer->addTemplateData($templateData);
+           $sent = $mailer->send();

            // If we are supposed to copy the sender, do so.
-
-           // Check whether email copy function activated
            if ($copy_email_activated == true && !empty($data['contact_email_copy']))
            {
-               $copytext = Text::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
-               $copytext .= "\r\n\r\n" . $body;
-               $copysubject = Text::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);
-
-               $mail = Factory::getMailer();
-               $mail->addRecipient($email);
-               $mail->addReplyTo($email, $name);
-               $mail->setSender([$mailfrom, $fromname]);
-               $mail->setSubject($copysubject);
-               $mail->setBody($copytext);
-               $sent = $mail->Send();
+               $mailer = new MailTemplate('com_contact.mail.copy', $app->getLanguage()->getTag());
+               $mailer->addRecipient($templateData['email']);
+               $mailer->setReplyTo($templateData['email'], $templateData['name']);
+               $mailer->addTemplateData($templateData);
+               $sent = $mailer->send();
            }
        }
        catch (MailDisabledException | phpMailerException $exception)
diff --git a/components/com_contact/src/Controller/ContactController.php b/components/com_contact/src/Controller/ContactController.php
index 03b157270b51..be1865a2f01a 100644
--- a/components/com_contact/src/Controller/ContactController.php
+++ b/components/com_contact/src/Controller/ContactController.php
@@ -15,6 +15,7 @@
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
 use Joomla\CMS\Mail\Exception\MailDisabledException;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\MVC\Controller\FormController;
 use Joomla\CMS\Plugin\PluginHelper;
 use Joomla\CMS\Router\Route;
@@ -241,18 +242,16 @@ private function _sendEmail($data, $contact, $copy_email_activated)
            $contact->email_to = $contact_user->get('email');
        }

-       $mailfrom = $app->get('mailfrom');
-       $fromname = $app->get('fromname');
-       $sitename = $app->get('sitename');
-
-       $name    = $data['contact_name'];
-       $email   = PunycodeHelper::emailToPunycode($data['contact_email']);
-       $subject = $data['contact_subject'];
-       $body    = $data['contact_message'];
-
-       // Prepare email body
-       $prefix = Text::sprintf('COM_CONTACT_ENQUIRY_TEXT', Uri::base());
-       $body   = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body);
+       $templateData = [
+           'sitename' => $app->get('sitename'),
+           'name'     => $data['contact_name'],
+           'contactname' => $contact->name,
+           'email'    => PunycodeHelper::emailToPunycode($data['contact_email']),
+           'subject'  => $data['contact_subject'],
+           'body'     => stripslashes($data['contact_message']),
+           'url'      => Uri::base(),
+           'customfields' => ''
+       ];

        // Load the custom fields
        if (!empty($data['com_fields']) && $fields = FieldsHelper::getFields('com_contact.mail', $contact, true, $data['com_fields']))
@@ -269,34 +268,26 @@ private function _sendEmail($data, $contact, $copy_email_activated)

            if ($output)
            {
-               $body .= "\r\n\r\n" . $output;
+               $templateData['customfields'] = $output;
            }
        }

        try
        {
-           $mail = Factory::getMailer();
-           $mail->addRecipient($contact->email_to);
-           $mail->addReplyTo($email, $name);
-           $mail->setSender(array($mailfrom, $fromname));
-           $mail->setSubject($sitename . ': ' . $subject);
-           $mail->setBody($body);
-           $sent = $mail->Send();
+           $mailer = new MailTemplate('com_contact.mail', $app->getLanguage()->getTag());
+           $mailer->addRecipient($contact->email_to);
+           $mailer->setReplyTo($templateData['email'], $templateData['name']);
+           $mailer->addTemplateData($templateData);
+           $sent = $mailer->send();

            // If we are supposed to copy the sender, do so.
            if ($copy_email_activated == true && !empty($data['contact_email_copy']))
            {
-               $copytext = Text::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
-               $copytext .= "\r\n\r\n" . $body;
-               $copysubject = Text::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);
-
-               $mail = Factory::getMailer();
-               $mail->addRecipient($email);
-               $mail->addReplyTo($email, $name);
-               $mail->setSender(array($mailfrom, $fromname));
-               $mail->setSubject($copysubject);
-               $mail->setBody($copytext);
-               $sent = $mail->Send();
+               $mailer = new MailTemplate('com_contact.mail.copy', $app->getLanguage()->getTag());
+               $mailer->addRecipient($templateData['email']);
+               $mailer->setReplyTo($templateData['email'], $templateData['name']);
+               $mailer->addTemplateData($templateData);
+               $sent = $mailer->send();
            }
        }
        catch (MailDisabledException | phpMailerException $exception)
diff --git a/components/com_users/src/Model/RemindModel.php b/components/com_users/src/Model/RemindModel.php
index 483bcc0b793f..0b845d5c342c 100644
--- a/components/com_users/src/Model/RemindModel.php
+++ b/components/com_users/src/Model/RemindModel.php
@@ -15,6 +15,7 @@
 use Joomla\CMS\Form\Form;
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\MVC\Model\FormModel;
 use Joomla\CMS\Router\Route;
 use Joomla\CMS\String\PunycodeHelper;
@@ -176,27 +177,18 @@ public function processRemindRequest($data)

        // Put together the email template data.
        $data = ArrayHelper::fromObject($user);
-       $data['fromname'] = $app->get('fromname');
-       $data['mailfrom'] = $app->get('mailfrom');
        $data['sitename'] = $app->get('sitename');
        $data['link_text'] = Route::_($link, false, $mode);
        $data['link_html'] = Route::_($link, true, $mode);

-       $subject = Text::sprintf(
-           'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT',
-           $data['sitename']
-       );
-       $body = Text::sprintf(
-           'COM_USERS_EMAIL_USERNAME_REMINDER_BODY',
-           $data['sitename'],
-           $data['username'],
-           $data['link_text']
-       );
+       $mailer = new MailTemplate('com_users.reminder', $app->getLanguage()->getTag());
+       $mailer->addTemplateData($data);
+       $mailer->addRecipient($user->email, $user->name);

        // Try to send the password reset request email.
        try
        {
-           $return = Factory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
+           $return = $mailer->send();
        }
        catch (\Exception $exception)
        {
diff --git a/components/com_users/src/Model/ResetModel.php b/components/com_users/src/Model/ResetModel.php
index ad8efc10d1af..dc9b420b36b2 100644
--- a/components/com_users/src/Model/ResetModel.php
+++ b/components/com_users/src/Model/ResetModel.php
@@ -16,6 +16,7 @@
 use Joomla\CMS\Form\Form;
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\MVC\Model\FormModel;
 use Joomla\CMS\Router\Route;
 use Joomla\CMS\String\PunycodeHelper;
@@ -472,29 +473,19 @@ public function processResetRequest($data)

        // Put together the email template data.
        $data = $user->getProperties();
-       $data['fromname'] = $app->get('fromname');
-       $data['mailfrom'] = $app->get('mailfrom');
        $data['sitename'] = $app->get('sitename');
        $data['link_text'] = Route::_($link, false, $mode);
        $data['link_html'] = Route::_($link, true, $mode);
        $data['token'] = $token;

-       $subject = Text::sprintf(
-           'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT',
-           $data['sitename']
-       );
-
-       $body = Text::sprintf(
-           'COM_USERS_EMAIL_PASSWORD_RESET_BODY',
-           $data['sitename'],
-           $data['token'],
-           $data['link_text']
-       );
+       $mailer = new MailTemplate('com_users.password_reset', $app->getLanguage()->getTag());
+       $mailer->addTemplateData($data);
+       $mailer->addRecipient($user->email, $user->name);

        // Try to send the password reset request email.
        try
        {
-           $return = Factory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $user->email, $subject, $body);
+           $return = $mailer->send();
        }
        catch (\Exception $exception)
        {
diff --git a/installation/sql/mysql/supports.sql b/installation/sql/mysql/supports.sql
index 8ab9f112f8f9..ee93005b0b8f 100644
--- a/installation/sql/mysql/supports.sql
+++ b/installation/sql/mysql/supports.sql
@@ -427,4 +427,11 @@ CREATE TABLE IF NOT EXISTS `#__mail_templates` (
 --

 INSERT INTO `#__mail_templates` (`template_id`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES
-('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
+('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}'),
+('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
+('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
+('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
+('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
+('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');
diff --git a/installation/sql/postgresql/supports.sql b/installation/sql/postgresql/supports.sql
index eaeae4bc19da..f4a75d0bbc45 100644
--- a/installation/sql/postgresql/supports.sql
+++ b/installation/sql/postgresql/supports.sql
@@ -438,4 +438,11 @@ CREATE INDEX "#__mail_templates_idx_language" ON "#__mail_templates" ("language"
 --

 INSERT INTO "#__mail_templates" ("template_id", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES
-('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}');
+('com_config.test_mail', '', 'COM_CONFIG_SENDMAIL_SUBJECT', 'COM_CONFIG_SENDMAIL_BODY', '', '', '{"tags":["sitename","method"]}'),
+('com_contact.mail', '', 'COM_CONTACT_ENQUIRY_SUBJECT', 'COM_CONTACT_ENQUIRY_TEXT', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_contact.mail.copy', '', 'COM_CONTACT_COPYSUBJECT_OF', 'COM_CONTACT_COPYTEXT_OF', '', '', '{"tags":["sitename","name","email","subject","body","url","customfields"]}'),
+('com_users.massmail.mail', '', 'COM_USERS_MASSMAIL_MAIL_SUBJECT', 'COM_USERS_MASSMAIL_MAIL_BODY', '', '', '{"tags":["subject","body","subjectprefix","bodysuffix"]}'),
+('com_users.password_reset', '', 'COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT', 'COM_USERS_EMAIL_PASSWORD_RESET_BODY', '', '', '{"tags":["name","email","sitename","link_text","link_html","token"]}'),
+('com_users.reminder', '', 'COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT', 'COM_USERS_EMAIL_USERNAME_REMINDER_BODY', '', '', '{"tags":["name","username","sitename","email","link_text","link_html"]}'),
+('plg_system_updatenotification.mail', '', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'),
+('plg_user_joomla.mail', '', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT', 'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY', '', '', '{"tags":["name","sitename","url","username","password","email"]}');
diff --git a/language/en-GB/com_contact.ini b/language/en-GB/com_contact.ini
index e25450cba26c..7dd542098bc0 100644
--- a/language/en-GB/com_contact.ini
+++ b/language/en-GB/com_contact.ini
@@ -18,8 +18,8 @@ COM_CONTACT_FILTER_SEARCH_DESC="Contact Filter Search"
 COM_CONTACT_CHECKED_OUT_BY="Checked out by %s"
 COM_CONTACT_CONTACT_MESSAGE_SUBJECT_LABEL="Subject"
 COM_CONTACT_CONTACT_SEND="Send Email"
-COM_CONTACT_COPYSUBJECT_OF="Copy of: %s"
-COM_CONTACT_COPYTEXT_OF="This is a copy of the following message you sent to %s via %s"
+COM_CONTACT_COPYSUBJECT_OF="Copy of: {SUBJECT}"
+COM_CONTACT_COPYTEXT_OF="This is a copy of the following message you sent to {CONTACTNAME} via {SITENAME}\n\n{BODY}"
 COM_CONTACT_COUNT="Contact count:"
 COM_CONTACT_COUNTRY="Country"
 COM_CONTACT_DEFAULT_PAGE_TITLE="Contacts"
@@ -29,7 +29,8 @@ COM_CONTACT_EDIT_CONTACT="Edit Contact"
 COM_CONTACT_EMAIL_FORM="Contact Form"
 COM_CONTACT_EMAIL_LABEL="Email"
 COM_CONTACT_EMAIL_THANKS="Thank you for your email."
-COM_CONTACT_ENQUIRY_TEXT="This is an enquiry email via %s from:"
+COM_CONTACT_ENQUIRY_SUBJECT="{SITENAME}: {SUBJECT}"
+COM_CONTACT_ENQUIRY_TEXT="This is an enquiry email via {URL} from:\n{NAME} <{EMAIL}>\n\n{BODY}\n\n{CUSTOMFIELDS}"
 COM_CONTACT_ERROR_CONTACT_NOT_FOUND="Contact not found"
 COM_CONTACT_FAX="Fax"
 COM_CONTACT_FAX_NUMBER="Fax: %s"
diff --git a/language/en-GB/com_users.ini b/language/en-GB/com_users.ini
index 4c8b7d90605b..db71eed18a97 100644
--- a/language/en-GB/com_users.ini
+++ b/language/en-GB/com_users.ini
@@ -14,8 +14,8 @@ COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_BODY="Hello administrator,\n\nA n
 COM_USERS_EMAIL_ACTIVATE_WITH_ADMIN_ACTIVATION_SUBJECT="Registration approval required for account of %s at %s"
 COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_BODY="Hello %s,\n\nYour account has been activated by an administrator. You can now login at %s using the username %s and the password you chose while registering."
 COM_USERS_EMAIL_ACTIVATED_BY_ADMIN_ACTIVATION_SUBJECT="Account activated for %s at %s"
-COM_USERS_EMAIL_PASSWORD_RESET_BODY="Hello,\n\nA request has been made to reset your %s account password. To reset your password, you will need to submit this verification code to verify that the request was legitimate.\n\nThe verification code is %s\n\nSelect the URL below and proceed with resetting your password.\n\n %s \n\nThank you."
-COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT="Your %s password reset request"
+COM_USERS_EMAIL_PASSWORD_RESET_BODY="Hello,\n\nA request has been made to reset your {SITENAME} account password. To reset your password, you will need to submit this verification code to verify that the request was legitimate.\n\nThe verification code is {TOKEN}\n\nSelect the URL below and proceed with resetting your password.\n\n {LINK_TEXT} \n\nThank you."
+COM_USERS_EMAIL_PASSWORD_RESET_SUBJECT="Your {SITENAME} password reset request"
 COM_USERS_EMAIL_REGISTERED_BODY="Hello %s,\n\nThank you for registering at %s.\n\nYou may now log in to %s using the following username and password:\n\nUsername: %s\nPassword: %s"
 COM_USERS_EMAIL_REGISTERED_BODY_NOPW="Hello %s,\n\nThank you for registering at %s.\n\nYou may now log in to %s using the username and password you registered with."
 COM_USERS_EMAIL_REGISTERED_NOTIFICATION_TO_ADMIN_BODY="Hello administrator, \n\nA new user '%s', username '%s', has registered at %s."
@@ -23,8 +23,8 @@ COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY="Hello %s,\n\nThank you for regi
 COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY_NOPW="Hello %s,\n\nThank you for registering at %s. Your account is created and must be activated before you can use it.\nTo activate the account select the following link or copy-paste it in your browser:\n%s \n\nAfter activation you may login to %s using the following username and the password you entered during registration:\n\nUsername: %s"
 COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY="Hello %s,\n\nThank you for registering at %s. Your account is created and must be verified before you can use it.\nTo verify the account select the following link or copy-paste it in your browser:\n %s \n\nAfter verification an administrator will be notified to activate your account. You'll receive a confirmation when it's done.\nOnce that account has been activated you may login to %s using the following username and password:\n\nUsername: %s\nPassword: %s"
 COM_USERS_EMAIL_REGISTERED_WITH_ADMIN_ACTIVATION_BODY_NOPW="Hello %s,\n\nThank you for registering at %s. Your account is created and must be verified before you can use it.\nTo verify the account select the following link or copy-paste it in your browser:\n %s \n\nAfter verification an administrator will be notified to activate your account. You'll receive a confirmation when it's done.\nOnce that account has been activated you may login to %s using the following username and the password you entered during registration:\n\nUsername: %s"
-COM_USERS_EMAIL_USERNAME_REMINDER_BODY="Hello,\n\nA username reminder has been requested for your %s account.\n\nYour username is %s.\n\nTo login to your account, select the link below.\n\n%s \n\nThank you."
-COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT="Your %s username"
+COM_USERS_EMAIL_USERNAME_REMINDER_BODY="Hello,\n\nA username reminder has been requested for your {SITENAME} account.\n\nYour username is {USERNAME}.\n\nTo login to your account, select the link below.\n\n{LINK_TEXT} \n\nThank you."
+COM_USERS_EMAIL_USERNAME_REMINDER_SUBJECT="Your {SITENAME} username"
 COM_USERS_ERROR_SECRET_CODE_WITHOUT_TFA="You have entered a Secret Code but two factor authentication is not enabled in your user account. If you want to use a secret code to secure your login please edit your user profile and enable two factor authentication."
 COM_USERS_FIELD_PASSWORD_RESET_DESC="Please enter the email address associated with your User account.<br>A verification code will be sent to you. Once you have received the verification code, you will be able to choose a new password for your account."
 COM_USERS_FIELD_PASSWORD_RESET_LABEL="Email Address"
diff --git a/libraries/src/Mail/MailTemplate.php b/libraries/src/Mail/MailTemplate.php
index b3f2274fd3f0..55eb446cd4e7 100644
--- a/libraries/src/Mail/MailTemplate.php
+++ b/libraries/src/Mail/MailTemplate.php
@@ -70,6 +70,14 @@ class MailTemplate
     */
    protected $recipients = array();

+   /**
+    * Reply To of the email
+    *
+    * @var    \stdClass
+    * @since  4.0.0
+    */
+   protected $replyto;
+
    /**
     * Constructor for the mail templating class
     *
@@ -123,15 +131,33 @@ public function addAttachment($name, $file)
     *
     * @since   4.0.0
     */
-   public function addRecipient($mail, $name, $type = 'to')
+   public function addRecipient($mail, $name = null, $type = 'to')
    {
        $recipient = new \stdClass;
        $recipient->mail = $mail;
-       $recipient->name = $name;
+       $recipient->name = $name ?? $mail;
        $recipient->type = $type;
        $this->recipients[] = $recipient;
    }

+   /**
+    * Set reply to for this mail
+    *
+    * @param   string  $mail  Mail address to reply to
+    * @param   string  $name  Name
+    *
+    * @return  void
+    *
+    * @since   4.0.0
+    */
+   public function setReplyTo($mail, $name = '')
+   {
+       $reply = new \stdClass;
+       $reply->mail = $mail;
+       $reply->name = $name;
+       $this->replyto = $reply;
+   }
+
    /**
     * Add data to replace in the template
     *
@@ -240,6 +266,11 @@ public function send()
            }
        }

+       if ($this->replyto)
+       {
+           $this->mailer->addReplyTo($this->replyto->mail, $this->replyto->name);
+       }
+
        $path = JPATH_ROOT . '/' . $config->get('attachment_folder') . '/';

        foreach ((array) json_decode($mail->attachments)  as $attachment)
@@ -282,21 +313,23 @@ protected function replaceTags($text, $tags)
            if (is_array($value))
            {
                $matches = array();
-               preg_match_all('/{' . strtoupper($key) . '}(.*?){/' . strtoupper($key) . '}/s', $text, $matches);

-               foreach ($matches[0] as $i => $match)
+               if (preg_match_all('/{' . strtoupper($key) . '}(.*?){\/' . strtoupper($key) . '}/s', $text, $matches))
                {
-                   $replacement = '';
-
-                   foreach ($value as $subvalue)
+                   foreach ($matches[0] as $i => $match)
                    {
-                       if (is_array($subvalue))
+                       $replacement = '';
+
+                       foreach ($value as $subvalue)
                        {
-                           $replacement .= $this->replaceTags($matches[1][$i], $subvalue);
+                           if (is_array($subvalue))
+                           {
+                               $replacement .= $this->replaceTags($matches[1][$i], $subvalue);
+                           }
                        }
-                   }

-                   $text = str_replace($match, $replacement, $text);
+                       $text = str_replace($match, $replacement, $text);
+                   }
                }
            }
            else
diff --git a/plugins/system/updatenotification/updatenotification.php b/plugins/system/updatenotification/updatenotification.php
index 7b0d82d662bd..01c70acc8684 100644
--- a/plugins/system/updatenotification/updatenotification.php
+++ b/plugins/system/updatenotification/updatenotification.php
@@ -17,6 +17,7 @@
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
 use Joomla\CMS\Mail\Exception\MailDisabledException;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\Plugin\CMSPlugin;
 use Joomla\CMS\Table\Table;
 use Joomla\CMS\Updater\Updater;
@@ -242,11 +243,6 @@ public function onAfterRender()
            $jLanguage->load('plg_system_updatenotification', JPATH_ADMINISTRATOR, $forcedLanguage, true, false);
        }

-       // Set up the email subject and body
-
-       $email_subject = Text::_('PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_SUBJECT');
-       $email_body    = Text::_('PLG_SYSTEM_UPDATENOTIFICATION_EMAIL_BODY');
-
        // Replace merge codes with their values
        $newVersion = $update->version;

@@ -254,36 +250,25 @@ public function onAfterRender()
        $currentVersion = $jVersion->getShortVersion();

        $sitename = $this->app->get('sitename');
-       $mailFrom = $this->app->get('mailfrom');
-       $fromName = $this->app->get('fromname');

        $substitutions = [
-           '[NEWVERSION]'  => $newVersion,
-           '[CURVERSION]'  => $currentVersion,
-           '[SITENAME]'    => $sitename,
-           '[URL]'         => Uri::base(),
-           '[LINK]'        => $uri->toString(),
-           '[RELEASENEWS]' => 'https://www.joomla.org/announcements/release-news/',
-           '\\n'           => "\n",
+           'newversion'  => $newVersion,
+           'curversion'  => $currentVersion,
+           'sitename'    => $sitename,
+           'url'         => Uri::base(),
+           'link'        => $uri->toString(),
+           'releasenews' => 'https://www.joomla.org/announcements/release-news/'
        ];

-       foreach ($substitutions as $k => $v)
-       {
-           $email_subject = str_replace($k, $v, $email_subject);
-           $email_body    = str_replace($k, $v, $email_body);
-       }
-
        // Send the emails to the Super Users
        foreach ($superUsers as $superUser)
        {
            try
            {
-               $mailer = Factory::getMailer();
-               $mailer->setSender([$mailFrom, $fromName]);
+               $mailer = new MailTemplate('plg_system_updatenotification.mail', $jLanguage->getTag());
                $mailer->addRecipient($superUser->email);
-               $mailer->setSubject($email_subject);
-               $mailer->setBody($email_body);
-               $mailer->Send();
+               $mailer->addTemplateData($substitutions);
+               $mailer->send();
            }
            catch (MailDisabledException | phpMailerException $exception)
            {
diff --git a/plugins/user/joomla/joomla.php b/plugins/user/joomla/joomla.php
index b37e21a92cf5..8c7ee2f1f766 100644
--- a/plugins/user/joomla/joomla.php
+++ b/plugins/user/joomla/joomla.php
@@ -14,6 +14,7 @@
 use Joomla\CMS\Language\LanguageFactoryInterface;
 use Joomla\CMS\Language\Text;
 use Joomla\CMS\Log\Log;
+use Joomla\CMS\Mail\MailTemplate;
 use Joomla\CMS\Plugin\CMSPlugin;
 use Joomla\CMS\Uri\Uri;
 use Joomla\CMS\User\User;
@@ -201,32 +202,23 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
        // Load plugin language files.
        $this->loadLanguage();

-       // Compute the mail subject.
-       $emailSubject = Text::sprintf(
-           'PLG_USER_JOOMLA_NEW_USER_EMAIL_SUBJECT',
-           $user['name'],
-           $this->app->get('sitename')
-       );
-
-       // Compute the mail body.
-       $emailBody = Text::sprintf(
-           'PLG_USER_JOOMLA_NEW_USER_EMAIL_BODY',
-           $user['name'],
-           $this->app->get('sitename'),
-           Uri::root(),
-           $user['username'],
-           $user['password_clear']
-       );
+       // Collect data for mail
+       $data = [
+           'name' => $user['name'],
+           'sitename' => $this->app->get('sitename'),
+           'url' => Uri::root(),
+           'username' => $user['username'],
+           'password' => $user['password_clear'],
+           'email' => $user['email']
+       ];
+
+       $mailer = new MailTemplate('plg_user_joomla.mail', $userLocale);
+       $mailer->addTemplateData($data);
+       $mailer->addRecipient($user['email'], $user['name']);

        try
        {
-           $res = Factory::getMailer()->sendMail(
-               $this->app->get('mailfrom'),
-               $this->app->get('fromname'),
-               $user['email'],
-               $emailSubject,
-               $emailBody
-           );
+           $res = $mailer->send();
        }
        catch (\Exception $exception)
        {
tecpromotion commented 4 years ago

depending on issue #804