diff --git a/src/classes/email.php b/src/classes/email.php index 4ebbf646..c766b443 100644 --- a/src/classes/email.php +++ b/src/classes/email.php @@ -12,6 +12,8 @@ namespace wishthis; +use Qferrer\Mjml\Renderer\ApiRenderer; + class Email { public function __construct( @@ -23,9 +25,17 @@ class Email public function send() { + global $options; + + $renderer = new ApiRenderer( + $options->getOption('mjml_api_key'), + $options->getOption('mjml_api_secret') + ); + $html = $renderer->render($this->mjml); + $to = $this->to; $subject = $this->subject; - $message = $this->mjml; + $message = $html; $headers = array( 'From' => 'no-reply@' . $_SERVER['HTTP_HOST'], 'Content-type' => 'text/html; charset=utf-8', diff --git a/src/mjml/password-reset.mjml b/src/mjml/password-reset.mjml new file mode 100644 index 00000000..c2c8295f --- /dev/null +++ b/src/mjml/password-reset.mjml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + a { + color: #6435c9; + } + .segment { + box-shadow: 0 1px 2px 0 rgba(34,36,38,.15); + } + + + + + + + + + + + + + + + + + + Hello, + + 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. + + Set new password + + + + + diff --git a/src/pages/login.php b/src/pages/login.php index 3fef6c3e..1185e5a9 100644 --- a/src/pages/login.php +++ b/src/pages/login.php @@ -6,7 +6,7 @@ * @author Jay Trees */ -use wishthis\Page; +use wishthis\{Page, Email}; $page = new Page(__FILE__, 'Login'); @@ -46,11 +46,15 @@ if (isset($_POST['reset'], $_POST['email'])) { $user = $database ->query('SELECT * FROM `users` - WHERE `email` = ' . $_POST['email'] . ';') + WHERE `email` = "' . $_POST['email'] . '";') ->fetch(); if ($user) { - $emailReset = new email($_POST['email']); + $mjml = file_get_contents(ROOT . '/src/mjml/password-reset.mjml'); + $mjml = str_replace('https://wishthis.online', $_SERVER['HTTP_HOST'], $mjml); + + $emailReset = new Email($_POST['email'], 'Password reset link', $mjml); + $emailReset->send(); } }