Personal portfolio website created with bootstrap.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

  1. <?php
  2. /**
  3. * This file validates input sent from a contact form in {@link index.html}.
  4. * After verifying that the captcha is correct, it sends the email
  5. * to my personal address.
  6. *
  7. * @author Jeffery Russell 6-17-18
  8. */
  9. $secret_file_path = '../captchaSecret.txt';
  10. $personal_email_path = '../email.txt';
  11. if(isset($_POST['submit']))
  12. {
  13. if(isset($_POST['g-recaptcha-response']))
  14. {
  15. $secret = file_get_contents($secret_file_path, FILE_USE_INCLUDE_PATH);
  16. $toEmail = file_get_contents($personal_email_path, FILE_USE_INCLUDE_PATH);
  17. if($secret === false)
  18. {
  19. echo "File with the captcha secret is not set:";
  20. echo $secret_file_path;
  21. }
  22. else if($toEmail === false)
  23. {
  24. echo "File with personal email address is not set:";
  25. echo $personal_email_path;
  26. }
  27. else
  28. {
  29. $response = $_POST["g-recaptcha-response"];
  30. $url = 'https://www.google.com/recaptcha/api/siteverify';
  31. $data = array(
  32. 'secret' => $secret,
  33. 'response' => $_POST["g-recaptcha-response"]
  34. );
  35. $options = array(
  36. 'http' => array (
  37. 'method' => 'POST',
  38. 'content' => http_build_query($data)
  39. )
  40. );
  41. $context = stream_context_create($options);
  42. $verify = file_get_contents($url, false, $context);
  43. $captcha_success=json_decode($verify);
  44. if ($captcha_success->success==false)
  45. {
  46. echo "<p>You are a bot! Go away!</p>";
  47. }
  48. else if ($captcha_success->success==true)
  49. {
  50. $fromName = stripslashes($_POST["name"]);
  51. $fromEmail = stripslashes($_POST["email"]);
  52. $subject = "Jrtechs.me Form Submission - " . $fromEmail;
  53. $emailMessage = stripslashes($_POST["message"]);
  54. $message = "Message from contact form on jrtechs.me\nName:
  55. $fromName \nEmail:\n$fromEmail \nMessage:\n$emailMessage";
  56. $headers = "From: $fromEmail";
  57. $response = $_POST[g-recaptcha-response];
  58. mail($toEmail, $subject, $message, $headers);
  59. header('Location:https://jrtechs.me/messageSent.html');
  60. }
  61. }
  62. }
  63. }