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_CONTACT, 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"); ?>