0
Hello, I put a form on my page and to load everything on the same page put the action=#contact (form section)
Even if I just click 1x on the SEND button, I get 2 identical emails.
Follows the contato.php who wear a include on the same home page:
<?
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT);
if(!empty($_GET) && $_SERVER['REQUEST_METHOD'] == 'GET'){
//pega as variaveis por POST
$nome = $_GET["nome"];
$email = $_GET["email"];
$fone = $_GET["fone"];
$assunto = $_GET["assunto"];
$mensagem = $_GET["mensagem"];
global $email; //função para validar a variável $email no script todo
$data = date("d/m/y"); //função para pegar a data de envio do e-mail
$hora = date("H:i"); //para pegar a hora com a função date
//aqui envia o e-mail para você
mail ("[email protected]", //email aonde o php vai enviar os dados do form
"$assunto",
"Nome: $nome\nData: $data\nHora: $hora\nE-mail: $email\nTelefone: $fone\n\nMensagem: $mensagem",
"From: $email"
);
//aqui são as configurações para enviar o e-mail para o visitante
$site = "[email protected]"; //o e-mail que aparecerá na caixa postal do visitante
$titulo = "Contato"; //titulo da mensagem enviada para o visitante
$msg = "$nome, Seu e-mail foi recebido!\nObrigado por entrar em contato conosco, em breve entraremos em contato!";
//aqui envia o e-mail de auto-resposta para o visitante
mail("$email",
"$titulo",
"$msg",
"From: $site"
);
}
?>
The main page looks something like this
<? include "contato.php";?>
<form action="#contato">
</form>
And at the end of the form I have another part in php to show the sending msg successfully
<?
if(!empty($_GET) && $_SERVER['REQUEST_METHOD'] == 'GET'){
echo "<p>Sua mensagem foi entregue com sucesso!<br>";
echo "Em até 48hrs você receberá um contato nosso. Obrigado!</p>";
}
?>
When I click send it sends an email and when it loads the page again it sends another email ?
Is there any way I can cancel the first or second shipment?
Have you tried printing the $email variable before and after the call to the global $email to see if that variable changes?
– Filipe Ricardo
Explain this one better
quando carrega a pagina de novo ele envia outro email, you’re sayingrefresh?– user60252
if refresh it will always send again because the url has the necessary parameters for sending and you are using
if(!empty($_GET) && $_SERVER['REQUEST_METHOD'] == 'GET'){– user60252
How is your form?
– user60252