From 84bfda64b948847eb13a056f4bca5f240fcf4cc5 Mon Sep 17 00:00:00 2001 From: divyesh000 Date: Sun, 2 Jun 2024 09:32:39 +0400 Subject: [PATCH] update Contact controller and view: add contact_us_successful flag, change email message generation, and add success dialog to view --- src/controllers/Contact.php | 16 +++++++----- src/views/Contact.php | 12 ++++++++- src/views/mails/Contact.php | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/views/mails/Contact.php diff --git a/src/controllers/Contact.php b/src/controllers/Contact.php index 2e9c577f..cacb7566 100644 --- a/src/controllers/Contact.php +++ b/src/controllers/Contact.php @@ -26,6 +26,8 @@ public function __construct() $this->view_data['defaultEmail'] = ""; $this->view_data['defaultMessage'] = ""; $this->view_data['errors'] = []; + $this->view_data['contact_us_successful'] = false; + } /** @@ -84,7 +86,7 @@ private function handleFormSubmission(): void if (empty($this->view_data['errors'])) { $success = $this->mailBusinessInbox($form_data); if ($success) { - Utility::redirect('home'); + $this->view_data['contact_us_successful'] = true; } else { (new Error())->handleMailingError(); } @@ -100,18 +102,18 @@ private function handleFormSubmission(): void */ private function mailBusinessInbox($form_data): bool { - // Concatenate form data into the email message - $htmlMessage = "You have received a new message from:
"; - $htmlMessage .= "Name: " . $form_data['first_name'] . " " . $form_data['last_name'] . "
"; - $htmlMessage .= "Email: " . $form_data['email'] . "
"; - $htmlMessage .= "Message: " . $form_data['message'] . "
"; + // Load the email template + ob_start(); + extract($form_data); + include __DIR__ . '/../views/mails/Contact.php'; + $htmlMessage = ob_get_clean(); $plainMessage = "You have received a new message from:\n"; $plainMessage .= "Name: " . $form_data['first_name'] . " " . $form_data['last_name'] . "\n"; $plainMessage .= "Email: " . $form_data['email'] . "\n"; $plainMessage .= "Message: " . $form_data['message'] . "\n"; - //Implement logic to send email to admin using Mailer class + // Implement logic to send email to admin using Mailer class $mailer = new Mailer(); $subject = "New Contact Message from " . $form_data['first_name'] . " " . $form_data['last_name']; diff --git a/src/views/Contact.php b/src/views/Contact.php index c524d514..8a242a2f 100644 --- a/src/views/Contact.php +++ b/src/views/Contact.php @@ -45,4 +45,14 @@ - \ No newline at end of file + + +> +
+

Thank You for Contacting Us! 🔎

+

Your message has been successfully sent. Our team will review your inquiry and get back to you shortly. We appreciate your interest in our services.

+ +
+
\ No newline at end of file diff --git a/src/views/mails/Contact.php b/src/views/mails/Contact.php new file mode 100644 index 00000000..3bf7c332 --- /dev/null +++ b/src/views/mails/Contact.php @@ -0,0 +1,51 @@ + + + + + + + New Contact Message + + + +
+

New Contact Message

+

Name:

+

Email:

+

Message:

+

+ +
+ +