es ist bereits 1 Woche, dass ich versuche, ein reCAPTCHA V2-Modul auf meiner statischen Website hinzuzufügen. (Ich habe die html5-Vorlage gekauft, da ich keine Erfahrung mit Web-Dev habe).Hinzufügen reCAPTCHA V2
Das ist mein HTML-Teil:
<form action="include/sendmail.php" method="post">
<div class="field">
<label class="required" for="sc_contact_form_username">Name</label>
<input type="text" name="username" id="sc_contact_form_username" />
</div>
<div class="field">
<label class="required" for="sc_contact_form_email">Email</label>
<input type="text" name="email" id="sc_contact_form_email" />
</div>
<div class="field message">
<label class="required" for="sc_contact_form_message">Your Message</label>
<textarea name="message" id="sc_contact_form_message"></textarea>
</div>
<div class="g-recaptcha" data-theme="dark" data-sitekey="MYKEY"></div>
<div class="button"> <a class="enter" href="#"><span>Submit</span></a> </div>
</form>
<div class="result sc_infobox"></div>
So weit so gut ... der schwierige Teil für mich ist es die PHP ist, wie ändere ich die aktuelle PHP die Validierung hinzuzufügen und es sicherer zu machen?
<?php
global $_REQUEST;
$response = array('error'=>'');
$user_name = substr($_REQUEST['user_name'], 0, 20);
$user_email = substr($_REQUEST['user_email'], 0, 40);
$user_msg = $_REQUEST['user_msg'];
$contact_email = '[email protected]';
if (trim($contact_email)!='') {
$subj = 'Message from ShiftCV HTML';
$msg = "Name: $user_name
E-mail: $user_email
Message: $user_msg";
$head = "Content-Type: text/plain; charset=\"utf-8\"\n"
. "X-Mailer: PHP/" . phpversion() . "\n"
. "Reply-To: $user_email\n"
. "To: $contact_email\n"
. "From: $user_email\n";
if ([email protected]($contact_email, $subj, $msg, $head)) {
$response['error'] = 'Error send message!';
}
} else
$response['error'] = 'Error send message!';
echo json_encode($response);
die();
?>
Ist es wirklich schwierig, ohne externe Bibliotheken zu implementieren? –