I have a problem in understanding the Google ReCatpcha, here is my html code
<form id="contact-form" class="contact-form" action="contact_form_handler.php" method="post" novalidate="novalidate">
<p>
<input id="name" class="required" name="name" type="text" placeholder="Nombre*" title="* Nombre">
</p>
<p>
<input id="email" class="email required" name="email" type="text" placeholder="Email*" title="* Email">
</p>
<p>
<input id="number" name="number" type="text" placeholder="Teléfono">
</p>
<p>
<textarea id="comment" class="required" name="message" placeholder="Consulta*" title="* Consulta"></textarea>
</p>
<div class="clearfix">
<div style="width:20%;" class="g-recaptcha" data-sitekey="6LfmbFQUAAAAABju6YU_SeON1f0kdbpVcluT1tGn"></div>
<input type="submit" id="submit-button" name="submit" class="btn-small btn-orange pull-right" value="Enviar mensaje">
<img src="images/ajax-loader.gif" id="ajax-loader" class="pull-right" alt="cargando...">
</div>
<div id="error-container"></div>
<div id="message-container"> </div>
and here is my php code, and insert the script and necessary div, the question lies in the php for the condition
<?php
/**
* File Name: contact_form_handler.php
*
* Send message function to process contact form submission
*
*/
if ( isset( $_POST['email'] ) ):
$name = filter_var( $_POST['name'], FILTER_SANITIZE_STRING );
$from_email = filter_var( $_POST['email'], FILTER_SANITIZE_EMAIL );
$number = filter_var( $_POST['number'], FILTER_SANITIZE_STRING );
$message = filter_var( $_POST['message'], FILTER_SANITIZE_STRING );
$to_email = "[email protected]"; // provide your target email address here
$to_name = "John Doe";
$email_subject = 'You Have Received a Message From ' . $name . '.';
if ( ! empty( $subject ) ) {
$email_subject = $subject . '.';
}
$email_body = "You have Received a message from: " . $name . " <br/>";
if (!empty( $number )) {
$email_body .= "Phone Number: " . $number . " <br/><br/>";
}
$email_body .= "Their additional message is as follows." . " <br/><br/>";
$email_content = nl2br( $message ) . " <br/><br/>";
$email_reply = "You can contact " . $name . " via email, " . $from_email ;
$prepared_message = $email_body . $email_content . $email_reply;
// You can consult https://github.com/eoghanobrien/php-simple-mail for more details
require 'class.simple_mail.php';
/* @var SimpleMail $mail */
$mail = new SimpleMail();
$mail->setTo( $to_email, $to_name )
->setSubject( $email_subject )
->setFrom( $from_email, $name )
->addMailHeader( 'Reply-To', $from_email, $name )
->addGenericHeader( 'X-Mailer', 'PHP/' . phpversion() )
->addGenericHeader( 'Content-Type', 'text/html; charset="utf-8"' )
->setMessage( $prepared_message );
$sent = $mail->send();
//echo $mail->debug();
if( $sent ) {
echo json_encode(array(
'success' => true,
'message' => "Message Sent Successfully!"
));
} else {
echo json_encode(array(
'success' => false,
'message' => "Server Error: mail method failed!"
)
);
}
else:
echo json_encode(array(
'success' => false,
'message' => "Invalid Request !"
)
);
endif;
die;