Guest User

Untitled

a guest
Feb 22nd, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. <?php
  2.  
  3. function post_captcha($user_response) {
  4. $fields_string = '';
  5. $fields = array(
  6. 'secret' => 'secret',
  7. 'response' => $user_response
  8. );
  9. foreach($fields as $key=>$value)
  10. $fields_string .= $key . '=' . $value . '&';
  11. $fields_string = rtrim($fields_string, '&');
  12.  
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  15. curl_setopt($ch, CURLOPT_POST, count($fields));
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
  18.  
  19. $result = curl_exec($ch);
  20. curl_close($ch);
  21.  
  22. return json_decode($result, true);
  23. }
  24.  
  25. $res = post_captcha($_POST['g-recaptcha-response']);
  26.  
  27. $name_error = $email_error = "";
  28. $name = $email = $message = $sent = "";
  29.  
  30. if (isset($_POST['submit']) AND (!$res['success'])) {
  31. // What happens when the CAPTCHA wasn't checked
  32. echo '<p>Please go back and make sure you check the security CAPTCHA box.</p><br>';
  33.  
  34. } else if ($_SERVER["REQUEST_METHOD"] == "POST") {
  35.  
  36. if (empty($_POST["name1"])) {
  37.  
  38. $name_error = "Name is required";
  39.  
  40.  
  41. } else {
  42.  
  43. $name = test_input($_POST["name1"]);
  44. // check if name only contains letters and whitespace
  45.  
  46. if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
  47. $name_error = "Only letters and white space allowed";
  48. }
  49. }
  50.  
  51. if (empty($_POST["email"])) {
  52.  
  53. $email_error = "Email is required";
  54.  
  55.  
  56. } else {
  57.  
  58. $email = test_input($_POST["email"]);
  59. // check if e-mail address is well-formed
  60. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  61. $email_error = "Invalid email format";
  62. }
  63. }
  64.  
  65. if (empty($_POST["message"])) {
  66.  
  67. $message = "";
  68.  
  69.  
  70. } else {
  71.  
  72. $message = test_input($_POST["message"]);
  73.  
  74.  
  75. }
  76.  
  77. if ($name_error == '' and $email_error == '' ){
  78.  
  79. $message_body = '';
  80.  
  81. unset($_POST['submit']);
  82.  
  83. foreach ($_POST as $key => $value){
  84.  
  85. $message_body .= "$key: $valuen";
  86.  
  87.  
  88. }
  89.  
  90.  
  91. $email = $_POST['email'];
  92. $to = 'devonfoodmovement@gmail.com';
  93. $subject = 'Contact Form Submit';
  94. $headers = 'From:' . $email . "n" . 'Reply-to: ' . $email . "n" ;
  95. if (mail($to, $subject, $message, $headers)) {
  96. $sent = "Message sent";
  97. $name = $email = $message = '';
  98. }
  99. }
  100. }
  101. function test_input($data) {
  102. $data = trim($data);
  103. $data = stripslashes($data);
  104. $data = htmlspecialchars($data);
  105. return $data;
  106. }
  107. ?>
  108.  
  109. <div class="grey">
  110. <div class="container-contact">
  111. <form id="contact" method="post">
  112. <div id="column-contact-left">
  113. <div class='contact-logo'></div>
  114. <h3>Contact the Devon Food Movement</h3>
  115. <fieldset id="field-no-ui">
  116. <input placeholder="Your name" type="text" tabindex="1" name="name1" value="<?= $name ?>" >
  117.  
  118. </fieldset>
  119. <span class="error"><?= $name_error ?></span>
  120. <fieldset id="field-no-ui">
  121. <input placeholder="Your Email Address" type="text" name="email" value="<?= $email ?>" tabindex="2" >
  122.  
  123. </fieldset>
  124. <span class="error"><?= $email_error ?></span>
  125. </div>
  126. <div id="column-contact-right">
  127. <fieldset id="field-no-ui">
  128. <textarea id="field-no-ui" placeholder="Type your Message Here...." name="message" value="<?= $message ?>" tabindex="3" ></textarea>
  129. </fieldset>
  130. <div class="g-recaptcha" data-sitekey="6LfJtkcUAAAAAE_7Ob_7BVMkaZMXX-dH-V6uqjCn" ></div>
  131. <span class="success"><?= $sent; ?></span>
  132. <fieldset id="field-no-ui">
  133. <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
  134. </fieldset>
  135. </div>
  136. </form>
  137. </div>
  138. </div>
Add Comment
Please, Sign In to add comment