diff --git a/src/api/wishlists.php b/src/api/wishlists.php
index a0265c86..7eb4f933 100644
--- a/src/api/wishlists.php
+++ b/src/api/wishlists.php
@@ -58,35 +58,34 @@ switch ($_SERVER['REQUEST_METHOD']) {
$href = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . Page::PAGE_WISHLISTS . '&id=' . $wishlist['id'];
/** Send email */
- $mjml = file_get_contents(ROOT . '/src/mjml/wishlist-request-wishes.mjml');
- $mjml = str_replace(
+ $user = new User($wishlist['user']);
+ $email = new Email($user->email, __('Wish request'), 'default', 'wishlist-request-wishes');
+ $email->mjml = str_replace(
'TEXT_HELLO',
__('Hello,'),
- $mjml
+ $email->mjml
);
- $mjml = str_replace(
+ $email->mjml = str_replace(
'TEXT_WISHLIST_REQUEST_WISHES',
sprintf(
/** TRANSLATORS: %s: Wishlist name */
__('somebody has requested that you add more wishes to your wishlist %s.'),
'' . $wishlist['name'] . ''
),
- $mjml
+ $email->mjml
);
- $mjml = str_replace(
+ $email->mjml = str_replace(
'TEXT_WISH_ADD',
__('Add wish'),
- $mjml
+ $email->mjml
);
- $mjml = str_replace(
+ $email->mjml = str_replace(
'LINK_WISH_ADD',
$href . '&wish_add=true',
- $mjml
+ $email->mjml
);
- $user = new User($wishlist['user']);
- $emailRequest = new Email($user->email, __('Wish request'), $mjml);
- $success = $emailRequest->send();
+ $success = $email->send();
/** Save date to database */
if (true === $success) {
diff --git a/src/classes/email.php b/src/classes/email.php
index 39919577..c8df9a15 100644
--- a/src/classes/email.php
+++ b/src/classes/email.php
@@ -16,11 +16,16 @@ use Qferrer\Mjml\Renderer\ApiRenderer;
class Email
{
+ public string $mjml;
+
public function __construct(
private string $to,
private string $subject,
- private string $mjml
+ private string $template,
+ private string $part
) {
+ $this->mjml = file_get_contents(ROOT . '/src/mjml/' . $this->template . '.mjml');
+ $this->mjml = str_replace('MJML_PART', 'parts/' . $this->part . '.mjml');
}
public function send(): bool
diff --git a/src/mjml/default.mjml b/src/mjml/default.mjml
new file mode 100644
index 00000000..500f5645
--- /dev/null
+++ b/src/mjml/default.mjml
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ a {
+ color: #6435c9;
+ }
+ .segment {
+ box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/mjml/parts/head.mjml b/src/mjml/parts/head.mjml
deleted file mode 100644
index cc7e9fac..00000000
--- a/src/mjml/parts/head.mjml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-a {
- color: #6435c9;
-}
-.segment {
- box-shadow: 0 1px 2px 0 rgba(34,36,38,.15);
-}
-
diff --git a/src/mjml/parts/password-reset.mjml b/src/mjml/parts/password-reset.mjml
new file mode 100644
index 00000000..69428f92
--- /dev/null
+++ b/src/mjml/parts/password-reset.mjml
@@ -0,0 +1,11 @@
+
+
+
+ TEXT_HELLO
+
+ TEXT_PASSWORD_RESET
+
+ TEXT_SET_NEW_PASSWORD
+
+
+
diff --git a/src/mjml/parts/wishlist-request-wishes.mjml b/src/mjml/parts/wishlist-request-wishes.mjml
new file mode 100644
index 00000000..810f9c82
--- /dev/null
+++ b/src/mjml/parts/wishlist-request-wishes.mjml
@@ -0,0 +1,11 @@
+
+
+
+ TEXT_HELLO
+
+ TEXT_WISHLIST_REQUEST_WISHES
+
+ TEXT_WISH_ADD
+
+
+
diff --git a/src/mjml/password-reset.mjml b/src/mjml/password-reset.mjml
deleted file mode 100644
index 431ff71d..00000000
--- a/src/mjml/password-reset.mjml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TEXT_HELLO
-
- TEXT_PASSWORD_RESET
-
- TEXT_SET_NEW_PASSWORD
-
-
-
-
-
-
-
diff --git a/src/mjml/wishlist-request-wishes.mjml b/src/mjml/wishlist-request-wishes.mjml
deleted file mode 100644
index 56b5b6b7..00000000
--- a/src/mjml/wishlist-request-wishes.mjml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- TEXT_HELLO
-
- TEXT_WISHLIST_REQUEST_WISHES
-
- TEXT_WISH_ADD
-
-
-
-
-
-
-
diff --git a/src/pages/login.php b/src/pages/login.php
index 192bc38b..61515842 100644
--- a/src/pages/login.php
+++ b/src/pages/login.php
@@ -68,28 +68,28 @@ if (isset($_POST['reset'], $_POST['email'])) {
WHERE `id` = ' . $user['id'] . '
;');
- $mjml = file_get_contents(ROOT . '/src/mjml/password-reset.mjml');
- $mjml = str_replace(
+ $emailReset = new Email($_POST['email'], __('Password reset link'), 'default', 'password-reset');
+ $emailReset->mjml = str_replace(
'TEXT_HELLO',
__('Hello,'),
- $mjml
+ $emailReset->mjml
);
- $mjml = str_replace(
+ $emailReset->mjml = str_replace(
'TEXT_PASSWORD_RESET',
__('somebody has requested a password reset for this email address from wishthis.online. If this was you, click the button below to invalidate your current password and set a new one.'),
- $mjml
+ $emailReset->mjml
);
- $mjml = str_replace(
+ $emailReset->mjml = str_replace(
'TEXT_SET_NEW_PASSWORD',
__('Set new password'),
- $mjml
+ $emailReset->mjml
);
- $mjml = str_replace(
+ $emailReset->mjml = str_replace(
'wishthis.online',
$_SERVER['HTTP_HOST'],
$mjml
);
- $mjml = str_replace(
+ $emailReset->mjml = str_replace(
'password-reset-link',
$_SERVER['REQUEST_SCHEME'] . '://' .
$_SERVER['HTTP_HOST'] .
@@ -97,7 +97,6 @@ if (isset($_POST['reset'], $_POST['email'])) {
$mjml
);
- $emailReset = new Email($_POST['email'], __('Password reset link'), $mjml);
$emailReset->send();
$page->messages[] = Page::info(