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