1
Hi. I have a website that I’ve uploaded the google recaptcha to. The captcha works correctly, however, I cannot make an error display if the message is sent. The "message sent successfully" notification is displayed normally, but the "message NOT sent" notification does not appear at all. However, the rest works normally, the message is only sent if the captcha is completed. The only problem is the notification of not sent.
Follows the code
<div class="row">
<!--=== Contact Form ===-->
<form id="contact-form" class="col-sm-8 col-sm-offset-2" method="post" novalidate>
<div class="form-group">
<label class="control-label" for="contact-name">Nome</label>
<div class="controls">
<input id="contact-name" name="nome" placeholder="Seu nome" class="form-control requiredField" type="text" data-error-empty="Por favor entre com seu nome">
</div>
</div><!-- End name input -->
<div class="form-group">
<label class="control-label" for="contact-mail">Email</label>
<div class=" controls">
<input id="contact-mail" name="email" placeholder="Seu email" class="form-control requiredField" type="email" data-error-empty="Por favor entre com seu email" data-error-invalid="Invalid email address">
</div>
</div><!-- End email input -->
<div class="form-group">
<label class="control-label" for="contact-message">Mensagem</label>
<div class="controls">
<textarea id="contact-message" name="mensagem" placeholder="Sua mensagem" class="form-control requiredField" rows="8" data-error-empty="Por favor entre com seu mensagem"></textarea>
</div>
</div><!-- End textarea -->
<div class="g-recaptcha" data-sitekey="6LcvSg8UAAAAAAsOYcKHl2mxO_Uq-e7e9X58sc_I"></div>
<p class="text-center"><button name="submit" type="submit" class="btn btn-quattro" data-error-message="Error!" data-sending-message="Enviando..." data-ok-message="Mensagem Enviada"><i class="fa fa-paper-plane"></i><?= $modulo9->modulo9_button ?></button></p>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form><!-- End contact-form -->
<?php
if (isset($_POST['email']) && !empty($_POST['g-recaptcha-response']) && !empty($_POST['email'])) {
require_once 'sendmail.php';
if ($mail->Send()) {
echo "<p class='alert alert-success' id='msg_alert'> <strong>Obrigado !</strong> Seu e-mail foi entregue.</p>";
} else {
echo "<p class='alert alert-success' id='msg_alert'> <strong>Obrigado !</strong> Seu e-mail NÃO foi entregue.</p>";
}
}
?>
</div>
</div>
</section>
<?php endif; ?>
Thank you in advance.
The error is now another, the error message is displayed all the time, only disappears when the email is sent, where it gives place to successful message in sending. It’s the only problem now. This message only needs to be hidden by default and display only when Else is called, but is displaying all the time.
What I’m using is:
<?php
require_once 'sendmail.php';
if (isset($_POST['email']) && !empty($_POST['g-recaptcha-response']) && !empty($_POST['email']) && $mail->Send()) {
echo "<p class='alert alert-success' id='msg_alert'> <strong>Obrigado !</strong> Seu e-mail foi entregue.</p>";
} else {
echo "<p class='alert alert-danger' id='msg_alert'> <strong>Email não enviado.</strong> Verifique o Captcha e os outros campos.</p>";
}
?>
The library is phpmailer
The sendmail.php:
<?php
require_once './loader.php';
require_once './plugin/email/email.php';
global $mail;
$smtp = new Smtpr();
$smtp->getSmtp();
$mail->Port = $smtp->smtp_port;
$mail->Host = $smtp->smtp_host;
$mail->Username = $smtp->smtp_username;
$mail->From = $smtp->smtp_username;
$mail->Password = $smtp->smtp_password;
$mail->FromName = $smtp->smtp_fromname;
$mail->Subject = utf8_decode("Contato Via Site " . $site->site_meta_titulo);
$mail->AddBCC($smtp->smtp_bcc);
$mail->AddAddress($smtp->smtp_username);
$data = date('d/m/Y H:i');
$nome = $_POST['nome'];
$email = $_POST['email'];
$mensagem = $_POST['mensagem'];
$mail->AddReplyTo($email);
$body = "<b>Data da Mensagem: </b> $data <br />";
$body .= "<b>Nome:</b> $nome <br />";
$body .= "<b>E-mail:</b> $email <br />";
$body .= "<b>Mensagem: </b>$mensagem <br />";
$mail->Body = nl2br($body);
//$mail->Send();
?>
When sending fails is showing success message? Or does it show anything? Pay attention to the displayed text as well, since you are using the "Alert-Success" class for the fault message.
– mau humor
When sending fails, shows nothing.
– Raphael Cordeiro
I only kept the Alert-Success class to test if that way it would work.
– Raphael Cordeiro