Guest User

Untitled

a guest
Feb 22nd, 2018
347
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. $subject = 'Contact Form Submit';
  93. $headers = 'From:' . $email . "n" . 'Reply-to: ' . $email . "n" ;
  94. if (mail($to, $subject, $message, $headers)) {
  95. $sent = "Message sent";
  96. $name = $email = $message = '';
  97. }
  98. }
  99. }
  100. function test_input($data) {
  101. $data = trim($data);
  102. $data = stripslashes($data);
  103. $data = htmlspecialchars($data);
  104. return $data;
  105. }
  106. ?>
  107.  
  108. <div class="grey">
  109. <div class="container-contact">
  110. <form id="contact" method="post">
  111. <div id="column-contact-left">
  112. <div class='contact-logo'></div>
  113. <h3>Contact the Devon Food Movement</h3>
  114. <fieldset id="field-no-ui">
  115. <input placeholder="Your name" type="text" tabindex="1" name="name1" value="<?= $name ?>" >
  116.  
  117. </fieldset>
  118. <span class="error"><?= $name_error ?></span>
  119. <fieldset id="field-no-ui">
  120. <input placeholder="Your Email Address" type="text" name="email" value="<?= $email ?>" tabindex="2" >
  121.  
  122. </fieldset>
  123. <span class="error"><?= $email_error ?></span>
  124. </div>
  125. <div id="column-contact-right">
  126. <fieldset id="field-no-ui">
  127. <textarea id="field-no-ui" placeholder="Type your Message Here...." name="message" value="<?= $message ?>" tabindex="3" ></textarea>
  128. </fieldset>
  129. <div class="g-recaptcha" data-sitekey="6LfJtkcUAAAAAE_7Ob_7BVMkaZMXX-dH-V6uqjCn" ></div>
  130. <span class="success"><?= $sent; ?></span>
  131. <fieldset id="field-no-ui">
  132. <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
  133. </fieldset>
  134. </div>
  135. </form>
  136. </div>
  137. </div>
Add Comment
Please, Sign In to add comment