Problema com formulário de contato ao jogar no servidor.
Galera,
Estou com um problema de quando mando o formulário de contato vai pro ar, ele simplesmente não funciona.
No meu servidor local ele funfa normalmente. Tenho quase certeza que esse problema ocorre com o google recaptcha,
porém as chaves estão corretas, fiz tudo conforme a API do google menciona, e estou seriamente a ter que usar ele :(
Então que já implementou sites com esse Recaptcha, pode dar uma força ! =D
segue o código que estou usando ..
<!-- form -->
<div class="form-contato">
<?php
// # VALIDANDO DADOS # //
$postD = filter_input(INPUT_POST, 'SendPostForm', FILTER_DEFAULT);
$message = NULL;
$data = [];
if ($postD) {
$dataSet = filter_input_array(INPUT_POST, FILTER_DEFAULT);
unset($dataSet['SendPostForm']);
$dataGet = array_map('strip_tags', $dataSet);
$data = array_map('trim', $dataGet);
$GoogleRecaptcha = new GoogleRecaptcha();
$verifyGoogleRecaptcha = $GoogleRecaptcha->VerifyCaptcha($data['g-recaptcha-response']);
if(!$verifyGoogleRecaptcha) {
$message = '';
echo '<div class="alert alert-danger">';
echo '<button type="button" class="close" data-dismiss="alert">×</button>';
echo '<strong> <i class="fa fa-exclamation-triangle"></i> Error, </strong> Para nos enviar a mensagem, é necessário marcar a caixa do Google Recaptcha. Obrigado(a)';
echo '</div>';
} else {
if(in_array('',$data)) {
echo '<div class="alert alert-danger">';
echo '<button type="button" class="close" data-dismiss="alert">×</button>';
echo '<strong> <i class="fa fa-exclamation-triangle"></i> Erro </strong>ao enviar sua mensagem, tente novamente.';
echo '</div>';
} else {
// # Envia Mail # //
$mail = new Mailer();
$MailContent = '<h2 style="margin:20px 0 0;"> Deborah Braga [ Contato pelo Site ]. </h2> <br> <h3 style="margin:0 0 5px;"> Os Dados Enviados Foram: </h3> <br>';
$MailContent .= ' <b style="font-size:1.4em;">Nome:</b> '.$data['nome'].'<br>';
$MailContent .= ' <b style="font-size:1.4em;">Email:</b> '.$data['email'].'<br>';
$MailContent .= ' <b style="font-size:1.4em;">Assunto:</b> '.$data['assunto'].'<br>';
$MailContent .= ' <b style="font-size:1.4em;">Mensagem:</b> '.$data['msg'].'<br>';
$sendMail = $mail->sendMailPhpMailer('Deborah Braga [ Contato pelo Site ] - '.$data['nome'].' - ' .$data['email'],$MailContent ,$data['email'],$data['nome'],'maciellweb@gmail.com','DeborahBraga');
echo '<div class="alert alert-success">';
echo '<button type="button" class="close" data-dismiss="alert">×</button>';
echo '<strong> <i class="fa fa-check"></i> Sucesso, </strong> Em breve retornaremos sua mensagem.';
echo '</div>';
}
}
}
?>
<form method="POST" id="formData" name="formData">
<input class="campo-preenchmento" type="text" placeholder="Nome" name="nome" value="<?php if (isset($data['nome'])) echo htmlspecialchars($data['nome']); ?>">
<input class="campo-preenchmento" type="text" placeholder="E-mail" name="email" value="<?php if (isset($data['email'])) echo htmlspecialchars($data['email']); ?>">
<input class="campo-preenchmento" type="text" placeholder="Assunto" name="assunto" value="<?php if (isset($data['assunto'])) echo htmlspecialchars($data['assunto']); ?>">
<textarea class="campo-mensagem" name="msg" value="<?php if (isset($data['objetivo'])) echo htmlspecialchars($data['msg']); ?>">
</textarea>
<!-- captcha -->
<div class="content-captcha">
<div class="campo-captcha">
<div style="position: relative; top: -16px; left: -8px;" class="g-recaptcha" data-sitekey="6LfP7QoTAAAAANWghgcl3ui6uDs2lZpJHMnt-2oj"></div>
</div>
<p style="font-size:.8em;">
Confirmação</br>
Recaptcha.
</p>
</div>
<input class="campo-enviar" type="submit" value="Enviar" name="SendPostForm">
</form>
</div>
google ReChaptcha
<?php
/**
* GOOGLE RECAPTCHA
*
* Classe Cujo Objetivo é o Gerenciamento e Verificação do Google Recaptcha.
*
* @copyright (c) 2015, Allyson Silva - AllysonWeb
* @version 1.0
* @author Allyson Silva <contato@allysonweb.com.br> <http://github.com/AllysonWeb>
* @license http://www.gnu.org/copyleft/gpl.txt GNU General Public License
* @link https://allysonweb.com.br/
*/
class GoogleRecaptcha
{
/**
* Url Da Google Para Verificação
* @var string
*/
private $google_url = "[https://www.google.com/recaptcha/](https://www.google.com/recaptcha/)api/siteverify";
/**
* Secret Key
* @link [https://www.google.com/recaptcha/](https://www.google.com/recaptcha/) Painel de Controle do Captcha
* @var string
*/
private $secret = '6LfP7QoTAAAAANdlPTpg4bqTHxCLKn_uLsmf1b4L';
/**
* Verificando Captcha.
* @param String $response String Response do Google Captcha.
* @return Boolean
*/
public function VerifyCaptcha($response)
{
$url = $this->google_url."?secret=".$this->secret."&response=".$response;
//# MÉDOTO FILE GET CONTENTS #//
$dataUrlVerify = file_get_contents($url, TRUE);
$res = json_decode($dataUrlVerify, TRUE);
if($res['success'] == 'true')
return TRUE;
else
return FALSE;
}
}
E o Mailer.php
<?php
/**
* MAILER PHP
*
* Classe Cujo Objetivo é Envio de Emails.
*
* @copyright (c) 2015, Allyson Silva - AllysonWeb
* @version 1.0
* @author Allyson Silva <contato@allysonweb.com.br> <http://github.com/AllysonWeb>
* @license http://www.gnu.org/copyleft/gpl.txt GNU General Public License
* @link https://allysonweb.com.br/
*/
class Mailer
{
/**
* SEND MAIL WITH PHP MAILER
*
* Método responsável por enviar email com o plugin php-mailer.
*
* @return Object Retorna todas as constantes em Array transformado para (Object)
* @author Allyson Silva { [http://allysonweb.com.br](http://allysonweb.com.br) } <contato@allysonweb.com.br>
* @api
* @copyrigh 2015 AllysonWeb
* @since 1.0.0
*/
public function sendMailPhpMailer($assunto,$mensagem,$remetente,$nomeRemetente,$destino,$nomeDestino, $reply = NULL, $replyNome = NULL)
{
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // Inicia a Classe //
$mail->IsSMTP(); // Habilita envio SMPT //
$mail->SMTPAuth = true; // Ativa Email Autenticado //
$mail->IsHTML(true);
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com'; // Servidor de Envio //
$mail->Port = 465; // Porta de Envio //
$mail->Username = 'meu@email'; // Email Para SMTP Autenticado //
$mail->Password = 'minhasenha';
$mail->From = utf8_decode($remetente); // Endereço Remetente //
$mail->FromName = utf8_decode($nomeRemetente); // Remetente Nome //
if($reply != NULL) {
$mail->AddReplyTo(utf8_decode($reply),utf8_decode($replyNome));
}
$mail->Subject = utf8_decode($assunto); // Assunto //
$mail->Body = utf8_decode($mensagem); // Mensagem //
$mail->AddAddress(utf8_decode($destino),utf8_decode($nomeDestino)); // Email e Nome de Destino //
if($mail->Send()) {
return true;
} else {
return false;
}
}
}
Desde já agradeço !!
sempre tem um cara fodão pra solucionar XD
Discussão (1)
Carregando comentários...