|
|
@@ -4,6 +4,55 @@ $page_title = "Contact";
|
|
|
|
|
|
Core::addBreadcrumb("/contact", $page_title);
|
|
|
|
|
|
+$submit = http::value("submit");
|
|
|
+if($submit) {
|
|
|
+ try {
|
|
|
+ Core::validateCSRFToken($submit);
|
|
|
+
|
|
|
+ $name = http::value("name", "trim");
|
|
|
+ $email = http::value("email", "email");
|
|
|
+ $phone = http::value("phone", "trim");
|
|
|
+ $message = http::value("message", "trim");
|
|
|
+
|
|
|
+ $form_exception = new FormException;
|
|
|
+
|
|
|
+ if(!Form::checkRecaptcha()) $form_exception->addError("reCAPTCHA check failed.");
|
|
|
+ if(empty($name)) $form_exception->addError("Name is required.");
|
|
|
+ if(empty($email)) $form_exception->addError("Email address is invalid.");
|
|
|
+ if(empty($phone)) $form_exception->addError("Contact number is required.");
|
|
|
+ if(empty($message)) $form_exception->addError("Message is required.");
|
|
|
+
|
|
|
+ if($form_exception->hasErrors()) throw $form_exception;
|
|
|
+
|
|
|
+ $mail = new Email();
|
|
|
+
|
|
|
+ $mail->loadHtmlTemplate("contact");
|
|
|
+ $mail->setValues([
|
|
|
+ "name" => htmlspecialchars($name),
|
|
|
+ "email" => htmlspecialchars($email),
|
|
|
+ "phone" => htmlspecialchars($phone),
|
|
|
+ "message" => htmlspecialchars($message),
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $mail->setFrom(EMAIL_FROM, EMAIL_FROM_NAME);
|
|
|
+ $mail->addAddress("admin@" . DOMAIN);
|
|
|
+ $mail->addReplyTo($email);
|
|
|
+
|
|
|
+ $mail->setSubject("New message received");
|
|
|
+
|
|
|
+ $mail->send();
|
|
|
+
|
|
|
+ Core::addAlert("success", "Message sent successfully. We will get back to you shortly.");
|
|
|
+ HTTP::redirect("/contact");
|
|
|
+ }
|
|
|
+ catch(FormException $e) {
|
|
|
+ $e->generateAlerts();
|
|
|
+ }
|
|
|
+ catch(Exception $e) {
|
|
|
+ Core::addAlert("danger", $e->getMessage());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
View::include("contact");
|
|
|
View::includeOnce("footer");
|