Jump to content

Custom contact us page with reCAPTCHA


Volkinson

Recommended Posts

Hi. Does somebody did custom contact us page with Google reCAPTCHA?

I found good script, on local site all working. But on WHMCS can't run. There is always some error to check captcha.

 

I have custom pages. I explain now, how i did all.

 

At the end of .tpl page, i inserted this:

{include_php file='/home/user/public_html/salescontactform.php'}

 

In php file i have this code:

<?php
   $to      = 'mail@kuda.com';
   $subject = 'Support Message';

   // keys from Google reCaptcha https://www.google.com/recaptcha/admin
   $sitekey = 'Sitekeytutbudet';
   $secretkey = 'SecretKeybudettut';

   $alert = '';
   if ($_SERVER['REQUEST_METHOD'] == 'POST')
   {
       $email;$message;$captcha;
       if(isset($_POST['email']))
                   $email=$_POST['email'];
              if(isset($_POST['message']))
                   $message=$_POST['message'];
           if(isset($_POST['g-recaptcha-response']))
               $captcha=$_POST['g-recaptcha-response'];

             if(!$captcha)
               $alert = '<div class="alert alert-warning" role="alert">Please wait until the captcha protection give you a check mark.</div>';

           $response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret='.$secretkey.'&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']));

       if($response->success==false)
       {
           /* lets set the error message for the alert... */
           if ($alert=='')
               $alert = '<div class="alert alert-danger" role="alert">Some how you have been detected has a spammer.</div>';
           }
       else
       {
           /* the email to you */
           $headers = 'From: '.$to.'' . "\r\n" .
                   'Reply-To: '.$email.'' . "\r\n" .
                   'X-Mailer: PHP/' . phpversion();
                   mail($to, $subject, $message, $headers);
           /* the copy of the email to the *client* */
           $headers = 'From: '.$email.'' . "\r\n" .
               'Reply-To: '.$to.'' . "\r\n" .
               'X-Mailer: PHP/' . phpversion();
           mail($email, 'COPY - '. $subject, $message, $headers);
           /* lets set the success message for the alert... */
           $alert = '<div class="alert alert-success" role="alert">Your email has been sent.</div>';
           }
   }
?>

<?=$alert?>


<form id="comment_form" action="" method="post">
   <input name="email" type="email" placeholder="Type your email" size="40" class="form-control" value="<?=@$email?>" ><br><br>
   <textarea name="message" rows="8" cols="39" class="form-control"  placeholder="Your message to us..." ><?=@$message?></textarea><br>
   <div class="g-recaptcha" data-sitekey="<?=$sitekey?>"></div><br>
   <input type="submit" name="submit" value="Send message" class="btn btn-default"><br>
</form>

<script src='https://www.google.com/recaptcha/api.js'></script>

 

Somehow i always receive error "Some how you have been detected has a spammer". Any clue, how to fix that? Or somebody have better ideas?

Thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated