diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 2bc7759620..0a067cc8fd 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1000,7 +1000,12 @@ App::post('/v1/account/sessions/magic-url') $customTemplate = $project->getAttribute('templates', [])['email.magicSession-' . $locale->default] ?? []; $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); - $message->setParam('{{body}}', $body); + $message + ->setParam('{{body}}', $body) + ->setParam('{{hello}}', $locale->getText("emails.magicSession.hello")) + ->setParam('{{footer}}', $locale->getText("emails.magicSession.footer")) + ->setParam('{{thanks}}', $locale->getText("emails.magicSession.thanks")) + ->setParam('{{signature}}', $locale->getText("emails.magicSession.signature")); $body = $message->render(); $smtp = $project->getAttribute('smtp', []); @@ -1050,16 +1055,7 @@ App::post('/v1/account/sessions/magic-url') } $emailVariables = [ - 'subject' => $subject, - 'hello' => $locale->getText("emails.magicSession.hello"), - 'body' => $body, - 'footer' => $locale->getText("emails.magicSession.footer"), - 'thanks' => $locale->getText("emails.magicSession.thanks"), - 'signature' => $locale->getText("emails.magicSession.signature"), 'direction' => $locale->getText('settings.direction'), - 'bg-body' => '#f7f7f7', - 'bg-content' => '#ffffff', - 'text-content' => '#000000', /* {{user}} ,{{team}}, {{project}} and {{redirect}} are required in the templates */ 'user' => '', 'team' => '', @@ -2457,7 +2453,12 @@ App::post('/v1/account/recovery') $customTemplate = $project->getAttribute('templates', [])['email.recovery-' . $locale->default] ?? []; $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); - $message->setParam('{{body}}', $body); + $message + ->setParam('{{body}}', $body) + ->setParam('{{hello}}', $locale->getText("emails.recovery.hello")) + ->setParam('{{footer}}', $locale->getText("emails.recovery.footer")) + ->setParam('{{thanks}}', $locale->getText("emails.recovery.thanks")) + ->setParam('{{signature}}', $locale->getText("emails.recovery.signature")); $body = $message->render(); $smtp = $project->getAttribute('smtp', []); @@ -2507,16 +2508,7 @@ App::post('/v1/account/recovery') } $emailVariables = [ - 'subject' => $subject, - 'hello' => $locale->getText("emails.recovery.hello"), - 'body' => $body, - 'footer' => $locale->getText("emails.recovery.footer"), - 'thanks' => $locale->getText("emails.recovery.thanks"), - 'signature' => $locale->getText("emails.recovery.signature"), 'direction' => $locale->getText('settings.direction'), - 'bg-body' => '#f7f7f7', - 'bg-content' => '#ffffff', - 'text-content' => '#000000', /* {{user}} ,{{team}}, {{project}} and {{redirect}} are required in the templates */ 'user' => $profile->getAttribute('name'), 'team' => '', @@ -2524,7 +2516,6 @@ App::post('/v1/account/recovery') 'redirect' => $url ]; - $queueForMails ->setRecipient($profile->getAttribute('email', '')) ->setName($profile->getAttribute('name')) @@ -2709,7 +2700,12 @@ App::post('/v1/account/verification') $customTemplate = $project->getAttribute('templates', [])['email.verification-' . $locale->default] ?? []; $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); - $message->setParam('{{body}}', $body); + $message + ->setParam('{{body}}', $body) + ->setParam('{{hello}}', $locale->getText("emails.verification.hello")) + ->setParam('{{footer}}', $locale->getText("emails.verification.footer")) + ->setParam('{{thanks}}', $locale->getText("emails.verification.thanks")) + ->setParam('{{signature}}', $locale->getText("emails.verification.signature")); $body = $message->render(); $smtp = $project->getAttribute('smtp', []); @@ -2759,16 +2755,7 @@ App::post('/v1/account/verification') } $emailVariables = [ - 'subject' => $subject, - 'hello' => $locale->getText("emails.verification.hello"), - 'body' => $body, - 'footer' => $locale->getText("emails.verification.footer"), - 'thanks' => $locale->getText("emails.verification.thanks"), - 'signature' => $locale->getText("emails.verification.signature"), 'direction' => $locale->getText('settings.direction'), - 'bg-body' => '#f7f7f7', - 'bg-content' => '#ffffff', - 'text-content' => '#000000', /* {{user}} ,{{team}}, {{project}} and {{redirect}} are required in the templates */ 'user' => $user->getAttribute('name'), 'team' => '', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index fe7759a6df..3c1b9417f5 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1718,7 +1718,6 @@ App::get('/v1/projects/:projectId/templates/email/:type/:locale') $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); $message ->setParam('{{hello}}', $localeObj->getText("emails.{$type}.hello")) - ->setParam('{{user}}', '') ->setParam('{{footer}}', $localeObj->getText("emails.{$type}.footer")) ->setParam('{{body}}', $localeObj->getText('emails.' . $type . '.body')) ->setParam('{{thanks}}', $localeObj->getText("emails.{$type}.thanks")) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 0a887908bb..2ee351f469 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -555,7 +555,12 @@ App::post('/v1/teams/:teamId/memberships') $customTemplate = $project->getAttribute('templates', [])['email.invitation-' . $locale->default] ?? []; $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); - $message->setParam('{{body}}', $body); + $message + ->setParam('{{body}}', $body) + ->setParam('{{hello}}', $locale->getText("emails.invitation.hello")) + ->setParam('{{footer}}', $locale->getText("emails.invitation.footer")) + ->setParam('{{thanks}}', $locale->getText("emails.invitation.thanks")) + ->setParam('{{signature}}', $locale->getText("emails.invitation.signature")); $body = $message->render(); $smtp = $project->getAttribute('smtp', []); @@ -606,16 +611,7 @@ App::post('/v1/teams/:teamId/memberships') $emailVariables = [ 'owner' => $user->getAttribute('name'), - 'subject' => $subject, - 'hello' => $locale->getText("emails.invitation.hello"), - 'body' => $body, - 'footer' => $locale->getText("emails.invitation.footer"), - 'thanks' => $locale->getText("emails.invitation.thanks"), - 'signature' => $locale->getText("emails.invitation.signature"), 'direction' => $locale->getText('settings.direction'), - 'bg-body' => '#f7f7f7', - 'bg-content' => '#ffffff', - 'text-content' => '#000000', /* {{user}} ,{{team}}, {{project}} and {{redirect}} are required in the templates */ 'user' => $user->getAttribute('name'), 'team' => $team->getAttribute('name'), diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 02c1835dd5..ade2125e4a 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -426,29 +426,31 @@ class Certificates extends Action $locale->setDefault('en'); } - $body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); - $subject = \sprintf($locale->getText("emails.certificate.subject"), $domain); - $body - ->setParam('{{domain}}', $domain) - ->setParam('{{error}}', $errorMessage) - ->setParam('{{attempt}}', $attempt) - ->setParam('{{subject}}', $subject) - ->setParam('{{hello}}', $locale->getText("emails.certificate.hello")) + + $message = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-inner-base.tpl'); + $message ->setParam('{{body}}', $locale->getText("emails.certificate.body")) - ->setParam('{{redirect}}', 'https://' . $domain) + ->setParam('{{hello}}', $locale->getText("emails.certificate.hello")) ->setParam('{{footer}}', $locale->getText("emails.certificate.footer")) ->setParam('{{thanks}}', $locale->getText("emails.certificate.thanks")) - ->setParam('{{signature}}', $locale->getText("emails.certificate.signature")) - ->setParam('{{project}}', 'Console') - ->setParam('{{direction}}', $locale->getText('settings.direction')) - ->setParam('{{bg-body}}', '#f7f7f7') - ->setParam('{{bg-content}}', '#ffffff') - ->setParam('{{text-content}}', '#000000'); + ->setParam('{{signature}}', $locale->getText("emails.certificate.signature")); + $body = $message->render(); + + $emailVariables = [ + 'direction' => $locale->getText('settings.direction'), + 'domain' => $domain, + 'error' => '
' . $errorMessage . '
', + 'attempt' => $attempt, + 'project' => 'Console', + 'redirect' => 'https://' . $domain, + ]; $queueForMails ->setRecipient(App::getEnv('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS')) - ->setBody($body->render()) + ->setSubject($subject) + ->setBody($body) + ->setVariables($emailVariables) ->setName('Appwrite Administrator') ->trigger(); } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 7a20212c9c..94a2a46087 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -58,13 +58,21 @@ class Mails extends Action $subject = $payload['subject']; $variables = $payload['variables']; $name = $payload['name']; - $body = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); + $body = $payload['body']; + $bodyTemplate = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); + $bodyTemplate->setParam('{{body}}', $body); foreach ($variables as $key => $value) { - $body->setParam('{{' . $key . '}}', $value); + $bodyTemplate->setParam('{{' . $key . '}}', $value); } + $body = $bodyTemplate->render(); - $body = $body->render(); + $subjectTemplate = Template::fromString($subject); + foreach ($variables as $key => $value) { + $subjectTemplate->setParam('{{' . $key . '}}', $value); + } + // render() will return the subject in

tags, so use strip_tags() to remove them + $subject = \strip_tags($subjectTemplate->render()); /** @var PHPMailer $mail */ $mail = empty($smtp)