如何将Recaptcha集成到我的mailer.php脚本中?

时间:2019-07-17 13:06:01

标签: php

我有一个contact.html文件,其中包含联系表格。这将使用mailer.php文件发布数据。

我正在尝试将RecaptchaV2集成到其中,但是它不起作用。

我尝试将这段代码添加到contact.html

我还在“提交”按钮上方的代码之间添加了此代码:

这是我的contact.html代码-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Contact Us!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="sfstyle.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-00000000"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-00000000');
</script>
</head>
<body>

<!-- ===============
Navigation 
=============== -->
<div class="container-fluid fixed-top" style="margin:0 auto;padding:0;opacity:0.8;background:#fff;text-align:center">
  <nav class="navbar navbar-expand-sm navbar-light">
    <div class="container-fluid navbrand">
    <a href="index.html" class="navbar-brand"><img src="img/sflogo.png" alt="Logo"></a>
      <button class="navbar-toggler custom-toggler" data-toggle="collapse" data-target="#hamburgerMenu"><span class="navbar-toggler-icon"></span></button>
      <div class="collapse navbar-collapse" id="hamburgerMenu">
        <ul class="navbar-nav ml-auto">
          <li class="nav-item"><a href="index.html" class="nav-link">Home</a></li>
          <li class="nav-item"><a href="about.html" class="nav-link">About</a></li>
          <li class="nav-item"><a href="services.html" class="nav-link">Services</a></li>
          <li class="nav-item"><a href="moving.html" class="nav-link">Moving Advice</a></li>
          <li class="nav-item"><a href="contact.html" class="nav-link">Contact / Quote Form</a></li>
        </ul>
      </div>
    </div>
  </nav>
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3" style="padding:5px;">
        <i class="fa fa-phone" style="background:#001a33;"></i>01925 387044 / 0778 490 9685
        </div>
        <div class="col-sm-7" style="text-align:center;padding:5px;">
        <a href="contact.html"><button type="button" class="btn btn-getquote" style="background:#001a33">Get A Quote!</button></a>
        </div>
        <div class="col-sm-2" style="padding:5px;">
        <a href="https://www.facebook.com/sfremovals1/"><i class="fa fa-facebook-square" aria-hidden="true" style="color:#3b5998;background:#fff;border:1px solid #3b5998;"></i></a>
        <a href="https://twitter.com/sfremovals"><i class="fa fa-twitter" aria-hidden="true" style="color:#00aced;background:#fff;border:1px solid #00aced;"></i></a>
        </div>      
      </div>
    </div>  
  </div>
 <!-- ===============
 Navigation End
 =============== -->
  <header id="home-section">
  <img src="img/headbg.jpg" alt="Header image">
  </header>

<div class="container" style="margin-top:40px;">
<div class="row">

<div class="col-sm-6">
<h1 style="text-align:center;">Get In Touch!</h1>
 <p>If you have any questions or require a quote, feel free to contact a member of staff on the contact information below.</p>
 <p>Alternatively, complete the contact form and a member of staff will respond as soon as possible to discuss any query you have</p>
</div>

<div class="col-sm-6">
          <div class="cpagecontact">
            <h3>Contact Us</h3>
            <div class="container"style="margin-top:10px;">
            <div class="row cpageadress">
            <div class="col-sm-1">
            <i class="fa fa-map-marker facpage" aria-hidden="true">
            </i></div>
            <div class="col-sm-11">
            Address
            </div>
            </div>

            <div class="row cpageadress">
            <div class="col-sm-1">
            <i class="fa fa-phone facpage" aria-hidden="true">
            </i></div>
            <div class="col-sm-11 cpagelink">
            <a href="tel:00000000000">00000000000</a> / <a href="tel:00000000000">+00000000000</a>
            </div>
            </div>

            <div class="row cpageadress">
            <div class="col-sm-1">
            <i class="fa fa-envelope facpage" aria-hidden="true">
            </i></div>
            <div class="col-sm-11 cpagelink">
            <a href="mailto:info@example.com">info@example.com</a>
            </div>
            </div>
            </div>

          </div>
</div>

</div>
</div>

 <div class="container" style="margin-top:40px;">
 <!-- ===============
Contact Form
 =============== -->
 <div class="row">

 <div class="col-sm-6">
 <form class="form-horizontal" name="contactform" method="post" action="mailer.php">
<!-- Form Name -->
<h3>Contact Form</h3>

<!-- Name -->
<div class="form-group">
  <label for="firstlastname" class="control-label col-sm-12">Name</label>
  <div class="col-sm-10">
    <input type="text" name="firstlastname" class="form-control" id="firstlastname" placeholder="First and Last Name - Required" required="">
   </div>
</div>

<!-- Email -->
<div class="form-group">
  <label for="email" class="control-label col-sm-12">Email</label>
  <div class="col-sm-10">
    <input type="email" name="email" class="form-control" id="email" placeholder="Email Address - Required" required="">
  </div>
</div>

<!-- Telephone -->
<div class="form-group">
  <label for="telephone" class="control-label col-sm-12">Phone Number</label>
  <div class="col-sm-10">
    <input type="tel"  name="telephone" class="form-control" id="telephone" placeholder="Contact Telephone Number">

  </div>
</div>

<!-- Property Type -->
<div class="form-group">
  <label for="ptype" class="control-label col-sm-12">Property Type</label>
  <div class="col-sm-10">
    <input type="text"  name="ptype" class="form-control" id="ptype" placeholder="Property Type (bought/rented)">

  </div>
</div>

<!-- From Address -->
<div class="form-group">
  <label class="control-label col-sm-12" for="faddress">From Address</label>
  <div class="col-sm-10">
    <textarea class="form-control" id="faddress" name="faddress" rows="1" required=""></textarea>
  </div>
</div>

<!-- To Address -->
<div class="form-group">
  <label class="control-label col-sm-12" for="taddress">To Address</label>
  <div class="col-sm-10">
    <textarea class="form-control" id="taddress" name="taddress" rows="1" required=""></textarea>
  </div>
</div>

<!-- Moving Items Description -->
<div class="form-group">
  <label class="control-label col-sm-12" for="itemsdescription">Moving Items Description</label>
  <div class="col-sm-10">
    <textarea class="form-control" id="itemsdescription" name="itemsdescription" rows="4" required=""></textarea>
  </div>
</div>

</div>


<div class="col-sm-6">

<!-- Disassembling requirements -->
<div class="form-group">
  <label class="control-label col-sm-12" for="disassemble">Disassembling Requirements</label>
  <div class="col-sm-10" style="text-align:left;">
    <input type="radio" class="" id="disassemble" name="disassemble" value="Yes">Yes<br>
    <input type="radio" class="" id="disassemble" name="disassemble" value="No" required="">No<br>
  </div>
</div>

<!-- Packaging requirements -->
<div class="form-group">
  <label class="control-label col-sm-12" for="packaging">Packaging Requirements</label>
  <div class="col-sm-10" style="text-align:left;">
    <input type="radio" class="" id="packaging" name="packaging" value="Yes">Yes<br>
    <input type="radio" class="" id="packaging" name="packaging" value="No" required="">No<br>
  </div>
</div>

<!-- dateandtime -->
<div class="form-group">
  <label for="dateandtime" class="control-label col-sm-12">Preferred Date and Time of Transport</label>
  <div class="col-sm-10">
    <input type="text"  name="dateandtime" class="form-control" id="dateandtime" placeholder="17/07/2017 11:00">

  </div>
</div>


<!-- Property Access -->
<div class="form-group">
  <label class="control-label col-sm-12" for="paccess">Properties Access</label>
  <div class="col-sm-10">
    <textarea class="form-control" id="paccess" name="paccess" rows="2" required=""></textarea>
  </div>
</div>

<!-- staircount -->
<div class="form-group">
  <label class="control-label col-sm-12" for="staircount">Flights of Stairs</label>
  <div class="col-sm-10">
    <input type="number" name="staircount" id="staircount" min="0" max="20" placeholder="0">
  </div>
</div>

<!-- Message -->
<div class="form-group">
  <label class="control-label col-sm-12" for="message">Message</label>
  <div class="col-sm-10">
    <textarea class="form-control" id="message" name="message" rows="5" placeholder="Message"></textarea>
  </div>
</div>

<!-- Button -->
<div class="form-group">
  <label class="control-label col-sm-12" for="singlebutton"></label>
  <div class="text-right col-sm-10">
    <input type="submit" id="singlebutton" name="singlebutton" class="btn btn-cpage" value="Submit Form">
  </div>
</div>
</form>
</div>


</div>
</div>  
<!-- ===============
Footer
=============== -->
    <div class="footer">
    <div class="container" class="footcontainer">
      <div class="row">
        <div class="col-sm-3 footmenu">
        <h5 class="footnavigateheader">Navigate</h5>
         <ul class="footlist">
           <li><a href="index.html">Home</a></li>
           <li><a href="about.html">About</a></li>
           <li><a href="services.html">Services</a></li>
           <li><a href="moving.html">Moving Advice</a></li>
           <li><a href="contact.html">Contact</a></li>
           <li><a href="terms.html">Terms & Conditions</a></li>
         </ul>
        </div>
        <div class="col-sm-6">
          <div class="footcontact">
            <h5 class="footnavigateheader">Contact Us</h5>

            <div class="row fadress">
            <div class="col-sm-1">
            <i class="fa fa-map-marker fafoot" aria-hidden="true">
            </i></div>
            <div class="col-sm-11">
            Superfast Deliveries and Removals<br>
            99 Reynolds Street<br> 
            Warrington<br> 
            WA4 1TY
            </div>
            </div>

            <div class="row fadress">
            <div class="col-sm-1">
            <i class="fa fa-phone fafoot" aria-hidden="true">
            </i></div>
            <div class="col-sm-11 footlist">
            <a href="tel:01925387044">01925 387044</a> / <a href="tel:07784909685">+44 778 490 9685</a>
            </div>
            </div>

            <div class="row fadress">
            <div class="col-sm-1">
            <i class="fa fa-envelope fafoot" aria-hidden="true">
            </i></div>
            <div class="col-sm-11 footlist">
            <a href="mailto:info@example.com">info@example.com</a>
            </div>
            </div>


          </div>
        </div>
<div class="container scoreandbuild">
<a href="https://smallseotools.com/website-seo-score-checker/" target="_blank"><img src="https://smallseotools.com/imgs/badge-golden-xs.png" alt="https://smallseotools.com/" /></a>
</div>  
          <div class="container-fluid copywright">
        © Copyright 2019 Superfast Removals & Deliveries All Rights Reserved.
      </div>
  </div>
<!-- ===============
Footer End
=============== -->



<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
</body>
</html>

这是我的mailer.php代码-

<?php
// $mail_to and $mail_from must be set.

$mail_to = 'info@example.com'; // Who is the E-Mail going to?
$mail_from = 'info@example.com'; // Where does the E-Mail appear to be from?

// OPTIONAL SETTING
$redirect_url = 'http://www.example.com/contact-thank-you.html'; // Example: http://example.com/thankyou.html - must be a FULL URL.

############################
# DO NOT EDIT BELOW THIS #
############################

// Fail if _POST and _GET are empty. Nothing to process.
if(count($_POST) == 0 AND count($_GET) == 0):
echo 'This form handler does nothing if visited directly. You must submit form data to this script.';
exit;
endif;

// Fail if $mail_to or $mail_from are not set.
if(empty($mail_to) OR empty($mail_from)):
echo 'You must edit this script and set the appropriate values for $mail_to and $mail_from.';
exit;
endif;

// Set $fields to whichever method is being used.
$fields = (count($_POST) > 0 ) ? $_POST : $_GET;

$message_body = "Form Submission \n\n";

foreach ($fields as $field => $value):
switch(strtolower($field)):
case 'redirect':
$redirect = $value;
case 'subject':
$subject = $value;
break;
endswitch;
if (strtolower($field) != 'redirect' AND strtolower($field) != 'submit' AND strtolower($field) != 'subject'):
$message_body .= strtoupper($field) . ": " . $value . "\n\n";
endif;
endforeach;

// Set the redirect URL from the form (if set). $host_url is a default action if $redirect isn't set
$redirect = (empty($redirect_url)) ? $redirect : $redirect_url;
$host_url = $_SERVER['HTTP_HOST'];

// Set the message subject based upon a subject field being set or not.

$message_subject = (!empty($subject)) ? $subject : 'Message from '.$_SERVER['HTTP_HOST'];

$headers = 'From: ' . $mail_from. "\r\n" .
'Reply-To: ' . $mail_from . "\r\n" .
'X-Mailer: PHP/' . phpversion();

// Remove potentially injected headers from the body

if (!mail($mail_to, $message_subject, $message_body, $headers)):
echo "Message Send Failed.";
endif;

if(empty($redirect)):
header("Location: http://{$host_url}");
else:
header("Location: {$redirect}");
endif;
?>

当我填写表单并单击“提交”而不完成Recaptcha时,将提交表单数据。 Recaptcha结果被忽略。

0 个答案:

没有答案