проверка Google reCAPTCHA v2 - PullRequest
       9

проверка Google reCAPTCHA v2

1 голос
/ 18 марта 2020

Я пытаюсь разработать контактную форму для моего веб-сайта жены.

Я нашел этот код, который работает очень хорошо и делает то, что ему нужно (Отправить копию отправителю сообщения)

Единственное, что я хочу объявить, - это Google Recaptcha v2. Я на самом деле не программист, но я пытаюсь вырезать и вставить немного кода вместе ... так что держите меня.

код, который я использую, я также нашел в Stackoverflow

Отправьте письмо с PHP из html формы при отправке с тем же сценарием

Я уже добавил recaptcha в html -часть. Но я не могу справиться с этим, чтобы иметь часть php, чтобы справиться с этим.

<html>
<head>
<title>Contact Formulier</title>
<script src="https://www.google.com/recaptcha/api.js"></script>
</head>
<body>
<form action="mail_handler.php" method="post">
First Name: <input type="text" name="first_name">
<br>
Last Name: <input type="text" name="last_name">
<br>
Email: <input type="text" name="email">
<br>
Phone: <input type="text" name="phone">
<br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<br>
<div class="g-recaptcha" data-sitekey="MY SITEKEY-CODE"></div>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php

if(isset($_POST['submit'])){

    $to = "info@mail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $phone = $_POST['phone'];
    $subject = "Mailform from www.website.com";

    $subject2 = "Copy of your message you have sent to www.website.com";

    $message = $first_name . " " . $last_name . "\n" . $from . "\n". $phone . "\n" ." wrote  this:" . "\n\n" . $_POST['message'];
    $message2 = $first_name . ", copy of your message : " ."\n\n" . $_POST['message'];
    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
    }
?>
...