Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. <?php
  2. /*
  3. Name: Contact Form
  4. Written by: Okler Themes - (http://www.okler.net)
  5. */
  6. ini_set('allow_url_fopen', true);
  7.  
  8. session_cache_limiter('nocache');
  9. header('Expires: ' . gmdate('r', 0));
  10.  
  11. header('Content-type: application/json');
  12.  
  13. require_once('php-mailer/PHPMailerAutoload.php');
  14.  
  15. if(isset($_POST['recaptcha']) && !empty($_POST['recaptcha'])) {
  16.  
  17. // Your Google reCAPTCHA generated Secret Key here
  18. $secret = '6LeG_RwUAAAAAGslb9LWdJ20Fcft3L7FgyiHedh6';
  19.  
  20. if( ini_get('allow_url_fopen') ) {
  21. //reCAPTCHA - Using file_get_contents()
  22. $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['recaptcha']);
  23. $responseData = json_decode($verifyResponse);
  24. } else if( function_exists('curl_version') ) {
  25. // reCAPTCHA - Using CURL
  26. $fields = array(
  27. 'secret' => $secret,
  28. 'response' => $_POST['recaptcha'],
  29. 'remoteip' => $_SERVER['REMOTE_ADDR']
  30. );
  31.  
  32. $verifyResponse = curl_init("https://www.google.com/recaptcha/api/siteverify");
  33. curl_setopt($verifyResponse, CURLOPT_RETURNTRANSFER, true);
  34. curl_setopt($verifyResponse, CURLOPT_TIMEOUT, 15);
  35. curl_setopt($verifyResponse, CURLOPT_POSTFIELDS, http_build_query($fields));
  36. $responseData = json_decode(curl_exec($verifyResponse));
  37. curl_close($verifyResponse);
  38. } else {
  39. $arrResult = array ('response'=>'error','errorMessage'=>'You need CURL or file_get_contents() activated in your server. Please contact your host to activate.');
  40. echo json_encode($arrResult);
  41. die();
  42. }
  43.  
  44. if($responseData->success) {
  45.  
  46. // Step 1 - Enter your email address below.
  47. $email = 'leads@mybusinessventure.com';
  48.  
  49. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  50. $debug = 0;
  51.  
  52. $subject = "MBVSites.com Contact Request *Intro";
  53.  
  54. $fields = array(
  55. 0 => array(
  56. 'text' => 'Name',
  57. 'val' => $_POST['name']
  58. ),
  59. 1 => array(
  60. 'text' => 'Email address',
  61. 'val' => $_POST['email']
  62. ),
  63. 2 => array(
  64. 'text' => 'State',
  65. 'val' => $_POST['state']
  66. ),
  67. 3 => array(
  68. 'text' => 'Phone',
  69. 'val' => $_POST['phone']
  70. )
  71. );
  72.  
  73. $message = '';
  74.  
  75. foreach($fields as $field) {
  76. $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  77. }
  78.  
  79. $mail = new PHPMailer(true);
  80.  
  81. try {
  82.  
  83. $mail->SMTPDebug = $debug; // Debug Mode
  84.  
  85. // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  86.  
  87. //$mail->IsSMTP(); // Set mailer to use SMTP
  88. //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
  89. //$mail->SMTPAuth = true; // Enable SMTP authentication
  90. //$mail->Username = 'user@example.com'; // SMTP username
  91. //$mail->Password = 'secret'; // SMTP password
  92. //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  93. //$mail->Port = 587; // TCP port to connect to
  94.  
  95. $mail->AddAddress($email); // Add another recipient
  96.  
  97. //$mail->AddAddress('person2@domain.com', 'Person 2'); // Add a secondary recipient
  98. //$mail->AddCC('person3@domain.com', 'Person 3'); // Add a "Cc" address.
  99. //$mail->AddBCC('person4@domain.com', 'Person 4'); // Add a "Bcc" address.
  100.  
  101. $mail->SetFrom($email, $_POST['name']);
  102. $mail->AddReplyTo($_POST['email'], $_POST['name']);
  103.  
  104. $mail->IsHTML(true); // Set email format to HTML
  105.  
  106. $mail->CharSet = 'UTF-8';
  107.  
  108. $mail->Subject = $subject;
  109. $mail->Body = $message;
  110.  
  111. $mail->Send();
  112. $arrResult = array ('response'=>'success');
  113.  
  114. } catch (phpmailerException $e) {
  115. $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  116. } catch (Exception $e) {
  117. $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  118. }
  119.  
  120. if ($debug == 0) {
  121. echo json_encode($arrResult);
  122. }
  123.  
  124. } else {
  125. $arrResult = array ('response'=>'error','errorMessage'=>'Robot verification failed, please try again');
  126. echo json_encode($arrResult);
  127. }
  128.  
  129. } else {
  130. $arrResult = array ('response'=>'error','errorMessage'=>'Please click on the reCAPTCHA box.');
  131. echo json_encode($arrResult);
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement