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;
// Content
$name = htmlspecialchars($name);
$email = htmlspecialchars($email);
$phone = htmlspecialchars($phone);
$message = htmlspecialchars($message);
// Build
$builder = new EmailBuilder;
$builder->addParagraph("Hi,");
$builder->addLeadParagraph("A new message was sent from the website!");
$builder->addParagraph("Name:
$name");
$builder->addParagraph("Email:
$email");
$builder->addParagraph("Contact Number:
$phone");
$builder->addParagraph("Message:
$message");
$content = $builder->build();
// Send
$mail = new Email;
$mail->setHtmlContent($content);
$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");
?>