Guest User

Untitled

a guest
Jul 9th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. <?php
  2.  
  3. /* VALIDATE RECAPTCHA */
  4. function validateRecaptcha($secret, $clientResponse, $clientIp)
  5. {
  6. $data = http_build_query([
  7. "LALALALAALA" => $secret,
  8. "response" => $clientResponse,
  9. "remoteip" => $clientIp,
  10. ]);
  11.  
  12. $options = [
  13. "http" => [
  14. "header" =>
  15. "Content-Type: application/x-www-form-urlencodedrn".
  16. "Content-Length: ".strlen($data)."rn",
  17. "method" => "POST",
  18. "content" => $data,
  19. ],
  20. ];
  21.  
  22. $response = file_get_contents(
  23. "https://www.google.com/recaptcha/api/siteverify",
  24. false,
  25. stream_context_create($options)
  26. );
  27.  
  28. if($response === false)
  29. {
  30. return false;
  31. }
  32. else if(($arr = json_decode($response, true)) === null)
  33. {
  34. return false;
  35. }
  36. else
  37. {
  38. return $arr["success"];
  39. }
  40. }
  41.  
  42.  
  43. $errorMSG = array();
  44.  
  45.  
  46. /* NAME */
  47.  
  48. if (empty($_POST["name"])) {
  49.  
  50. $errorMSG[] = "Name is required";
  51.  
  52. } else {
  53.  
  54. $name = $_POST["name"];
  55.  
  56. }
  57.  
  58.  
  59. /* EMAIL */
  60.  
  61. if (empty($_POST["email"])) {
  62.  
  63. $errorMSG[] = "Email is required";
  64.  
  65. } else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
  66.  
  67. $errorMSG[] = "Invalid email format";
  68.  
  69. }else {
  70.  
  71. $email = $_POST["email"];
  72.  
  73. }
  74.  
  75.  
  76. /* MSG SUBJECT */
  77.  
  78. if (empty($_POST["subject"])) {
  79.  
  80. $errorMSG[] = "Subject is required";
  81.  
  82. } else {
  83.  
  84. $subject = $_POST["subject"];
  85.  
  86. }
  87.  
  88.  
  89. /* MESSAGE */
  90.  
  91. if (empty($_POST["message"])) {
  92.  
  93. $errorMSG[] = "Message is required";
  94.  
  95. } else {
  96.  
  97. $message = $_POST["message"];
  98.  
  99. }
  100.  
  101. /* RECAPTCHA */
  102.  
  103. if (empty($_POST["g-recaptcha-response"])) {
  104.  
  105. $errorMSG[] = "ReCaptcha is required";
  106.  
  107. }
  108.  
  109.  
  110. if(empty($errorMSG)){
  111.  
  112. //PHPMailer
  113.  
  114. $mail = new PHPMailer;
  115.  
  116. //Enable SMTP debugging.
  117. $mail->SMTPDebug = 3;
  118. //Set PHPMailer to use SMTP.
  119. $mail->isSMTP();
  120. //Set SMTP host name
  121. $mail->Host = "smtp.server.com";
  122. //Set this to true if SMTP host requires authentication to send email
  123. $mail->SMTPAuth = true;
  124. //Provide username and password
  125. $mail->Username = "user@server.com";
  126. $mail->Password = "super_secret_password";
  127. //If SMTP requires TLS encryption then set it
  128. $mail->SMTPSecure = "tls";
  129. //Set TCP port to connect to
  130. $mail->Port = 587;
  131.  
  132. $mail->From = $emailAddress;
  133.  
  134. $mail->addAddress("name@server.com", "Recepient Name");
  135.  
  136. $mail->isHTML(true);
  137.  
  138. $mail->Subject = "Subject Text";
  139. $mail->Body = $emailBody;
  140.  
  141. $response = array();
  142.  
  143. if(!$mail->send())
  144. {
  145. $msg = "Email Failure";
  146. echo json_encode(['code'=>200, 'msg'=>$msg]);
  147. }
  148. else
  149. {
  150. $msg = "Form submit successfully";
  151. echo json_encode(['code'=>200, 'msg'=>$msg]);
  152. }
  153.  
  154. }
  155.  
  156.  
  157. ?>
Add Comment
Please, Sign In to add comment