From 2d6e12bfbf48cb59c8ed448734f81e93cab1a9df Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Wed, 22 May 2024 20:42:26 +0400 Subject: [PATCH] refactore sendResetEmail method to use an HTML template for email content --- src/controllers/Password.php | 22 +++++--- src/views/mails/PasswordReset.php | 89 +++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 src/views/mails/PasswordReset.php diff --git a/src/controllers/Password.php b/src/controllers/Password.php index 4f2298f6..3f0f728d 100644 --- a/src/controllers/Password.php +++ b/src/controllers/Password.php @@ -40,14 +40,22 @@ public function __construct() */ private function sendResetEmail(string $email, string $resetLink): void { - //Implement logic to send reset email using Mailer class - $mailer = new Mailer(); - $subject = "Reset Your Password | Steamy Sips"; - $htmlMessage = "Click the link below to reset your password:
$resetLink"; - $plainMessage = "Click the link below to reset your password:\n$resetLink"; - $mailer->sendMail($email, $subject, $htmlMessage, $plainMessage); - } + $subject = "Reset Your Password | Steamy Sips"; + + // Capture the HTML template content + ob_start(); + $userEmail = $email; + require __DIR__ . '/../views/mails/PasswordReset.php'; + $htmlMessage = ob_get_clean(); + // Plain message as fallback + $plainMessage = "Click the link below to reset your password:\n$resetLink"; + + // Send the email + $mailer = new Mailer(); + $mailer->sendMail($email, $subject, $htmlMessage, $plainMessage); + } + /** * Invoked when user submits an email on form. * @throws Exception Email could not be sent diff --git a/src/views/mails/PasswordReset.php b/src/views/mails/PasswordReset.php new file mode 100644 index 00000000..2120f770 --- /dev/null +++ b/src/views/mails/PasswordReset.php @@ -0,0 +1,89 @@ + + + + + + + + Reset Your Password + + + +
+
+ Steamy Sips Logo +
+
+

Reset Your Password

+

Hello,

+

We received a request to reset the password for the account associated with . Click the button below to reset your password:

+

Reset My Password

+

If you did not request a password reset, please ignore this email. This link will expire in 24 hours.

+

Thank you,
The Steamy Sips Team

+
+ +
+ +