0

When I try to click sent button, the content from the webpage is not redirecting to the .php page.I am using recaptcha in the form .Can you please help me to solve this issue..

my HTML code is:

<form action="sendform.php" id="contact-form" class="form-horizontal" 
   method="post">
   <fieldset>
      <div class="form-group">
         <label class="col-sm-4 control-label" for="name">Your Name</label>
         <div class="col-sm-8">
            <input type="text"  placeholder="Your Name" class="form-control" name="name" id="name">
         </div>
      </div>
      <div class="form-group">
         <label class="col-sm-4 control-label" for="email">Email Address</label>
         <div class="col-sm-8">
            <input type="text" placeholder="Enter Your Email Address" class="form-control" name="email" id="email">
         </div>
      </div>
      <div class="form-group">
         <label class="col-sm-4 control-label" for="subject">Subject</label>
         <div class="col-sm-8">
            <input type="text" placeholder="Subject" class="form-control" name="subject" id="subject" list="exampleList">
            <datalist  id="exampleList" >
               <option value="a">A</option>
               <option value="b">B Combo</option>
            </datalist>
         </div>
      </div>
      <div class="form-group">
         <label class="col-sm-4 control-label" for="message">Your Message</label>
         <div class="col-sm-8">
            <textarea placeholder="Please Type Your Message" class="form-control" name="message" id="message" rows="3"></textarea>
         </div>
      </div>
      <div class="col-sm-8"  class="form-group" class="g-recaptcha" data-sitekey="xxxxxxyyyyyyy"></div>
      <div class="col-sm-offset-4 col-sm-8">
         <button  type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l">Submit</button>
         <button type="reset" class="btn btn-primary">Cancel</button>   
      </div>
   </fieldset>
</form>

And my PHP Code sendform.php

    <?php
if (isset($_POST['submit']) && !empty($_POST['submit'])):
    if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
    //your site secret key
        $secret         = 'xxxxxxxxxxxxx';
    //get verify response data
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
        $responseData   = json_decode($verifyResponse);
        if ($responseData->success):
            $to      = "aaa@abc.com"; // this is your Email address
            $from    = !empty($_POST['email']) ? $_POST['email'] : ''; // this is the sender's Email address
            $name    = !empty($_POST['name']) ? $_POST['name'] : '';
            $subject = !empty($_POST['subject']) ? $_POST['subject'] : '';
            $subject2 = "Copy of your form submission";
            $message  = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
            $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
            $headers = "From:" . $from;
            $headers .= 'From:' . $name . ' <' . $from . '>' . "\r\n";
            $headers2 = "From:" . $to;

            mail($to, $subject, $message, $headers);
            $succMsg = 'Your request have submitted successfully.';
        else:
            $errMsg = 'Robot verification failed, please try again.';
        endif;
    else:
        $errMsg = 'Please click on the reCAPTCHA box.';
    endif;
else:
    $errMsg  = '';
    $succMsg = '';
endif;

?>
Deepu Sasidharan
  • 5,193
  • 10
  • 40
  • 97
Dona Susan Issac
  • 170
  • 1
  • 17

1 Answers1

0

I have tested your code and it works.

Please make sure that you have placed your html and php files in same directory and also your files should be served via a local running server.

So your url should look like this http://localhost/testing/index.html

Although, your sendform.php gives me captcha error ofcourse.

"Please click on the reCAPTCHA box."

Tahir Raza
  • 726
  • 1
  • 7
  • 20
  • two files are in same directory , and also i have clcik the recaptcha box all are done correctly .but it is not sending mail. – Dona Susan Issac Jun 12 '17 at 06:15
  • I said your url should look like mine. Mine won't work for you obviously as it is my **local**host – Tahir Raza Jun 12 '17 at 08:12
  • to send email from your localhost you have to check your configurations in php,ini. Remember mail function will not work in Local server in most of the cases. To be able to send email from localhost You need to config **SMTP** on your local server – Tahir Raza Jun 12 '17 at 08:28
  • i didn't get u what u saying . please in brief and understandable.. am not in local machine it is in server – Dona Susan Issac Jun 12 '17 at 10:09
  • if you are trying to send email from localhost, read [this](https://stackoverflow.com/questions/19132171/send-email-from-localhost-running-xammp-in-php-using-gmail-mail-server) and if you are on live server with shared hosting i guess then you should read [this](https://stackoverflow.com/questions/4733154/unable-to-send-mail-via-php-mail?rq=1) – Tahir Raza Jun 12 '17 at 11:19
  • this already i used .. am using host gator server here we can sent only to the server mail itself – Dona Susan Issac Jun 12 '17 at 11:40