1
Hello. I am suffering from spamming in my Portfolio contact form. I have already put the fields 'name', 'email' and 'message' as mandatory and with the tests I did, it is not possible to send without filling these fields. But every hour comes in my email that form sent only with the field completed email, are random emails. How do I make it stop? Is there any way to do it without putting Captcha on my form?
This is my form:
<form action="sendemail.php" method="post" id="contact-form" class="form-horizontal">
<fieldset>
<div class="form-group">
<div class="col-sm-8">
<input type="text" placeholder="Nome" class="form-control" name="nome" id="nome" required="Preencha o seu nome">
</div>
</div>
<div class="form-group">
<div class="col-sm-8">
<input type="text" placeholder="Email" class="form-control" name="email" id="email">
</div>
</div>
<div class="form-group">
<div class="col-sm-8">
<input type="text" placeholder="Assunto" class="form-control" name="assunto" id="assunto">
</div>
</div>
<div class="form-group">
<div class="col-sm-8">
<textarea placeholder="Mensagem" class="form-control" name="mensagem" id="mensagem" rows="3" required=""></textarea>
</div>
</div>
<div class="col-sm-8">
<button type="submit" class="btn btn-success">Enviar</button>
</div>
</fieldset>
</form>
And this is the file that sends the form:
<?php
if(isset($_POST['email'])) {
// Debes editar las próximas dos líneas de código de acuerdo con tus preferencias
$email_to = "[email protected]";
$email_subject = "Contato | Meu Portfólio";
$email_from = "marciaprates.com";
// Aquí se deberían validar los datos ingresados por el usuario
if(!isset($_POST['nome']) ||
!isset($_POST['email']) ||
!isset($_POST['assunto']) ||
!isset($_POST['mensagem'])) {
echo "<b>Não foi possível enviar o formulário. </b><br />";
echo "Por favor, tente novamente!<br />";
die();
}
$email_message = "Formulário do meu Portfólio:\n\n";
$email_message .= "Nome: " . $_POST['nome'] . "\n";
$email_message .= "E-mail: " . $_POST['email'] . "\n";
$email_message .= "Assunto: " . $_POST['assunto'] . "\n\n";
$email_message .= "Mensagem: " . $_POST['mensagem'] . "\n\n";
// Ahora se envía el e-mail usando la función mail() de PHP
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
echo "<b>O formulário foi enviado com sucesso!</b>";
}
?>
<script>
setTimeout('window.location.href="index.html"',1700)
</script>
Could someone please help me? I can’t take any more of these emails coming in every hour with just the filled email.
Thank you, I’ll try here and see if it works.
– Márcia Prates
You are welcome, I updated the answer and put an Obs, I think it will also help you.
– Bulfaitelo
The recapcha of google is very quiet when it is human filling it is only that boring bixo when to some suspicion, alias worked well ?
– Bulfaitelo
By then strlen(); is working. I’ll wait until tomorrow to see if I don’t get any more empty forms. If I don’t get it, I’ll just leave it to strlen. If not, I’ll test the recapcha. Thanks for the help :)
– Márcia Prates
show another tip, is this, a read in this question: https://stackoverflow.com/questions/5855811/how-to-validate-an-email-in-php it validates to know if the data entered is an email, I believe it is a validation relevant to your case, will ensure that the user has actually completed a valid email
– Bulfaitelo
Whoa, thanks. I’ll try to adapt to mine.
– Márcia Prates