Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
2 Email contact form Validation with security code in PHP

I'm having trouble making this properly work.

What I want to happen is for someone to be able to fill out the given information but there's an email validation which is just you put your email in Email: and is suppose to match in Verify Email: then in hopes that they did that write and if they answer the spam question right which is just "what is 5+5?" then the form will send to my email

The problem is that, although the email validation is working, the spam question even if you write the answer wrong, the form is still sent. I need it so that the spam and the email validation either or must be correct or the form won't send.

I hope made this simple for some to understand and help me out! Here's my PHP code. Let me know what I'm doing wrong.

<script>


<?php

$email1=$_POST['Email1'];
$email2=$_POST['Email2'];
$from=$_POST['Email1'];
$email="!YOUREMAIL@GOES.HERE!";
$subject="maintenance Request";
$message=$_POST['Box'];
$select=$_POST['Select'];
$name=$_POST['Name'];
$number=$_POST['Question'];
$message="Name:   ".$name. "\r\n" ."\r\n" . "Email:   " .$from ."\r\n" . "\r\n" . "Comment:   " .$message ."\r\n" . "\r\n" . "Selected Machine:   " .$select;


if($number==10) {

}


if(filter_var($email1, FILTER_VALIDATE_EMAIL)) {
}
if (filter_var($email2, FILTER_VALIDATE_EMAIL)) {
mail ($email, $subject, $message, "from:".$from);
echo 'Thanks You for the Maintenance Request! We will Contact you shortly. ';
}
else {
    echo "This ($email2) email address is different from ($email1).\n";
}

?>
</script>
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If the answer to the validation question is wrong, you should print a message and exit the script.

if ($number != 10) {
    die("You are not a human!");
}

You're also never checking if the two emails are the same.

if(!filter_var($email1, FILTER_VALIDATE_EMAIL)) {
    die("Invalid email ($email1)");
}
if ($email1 == $email2) {
    mail ($email, $subject, $message, "from:".$from);
    echo 'Thanks You for the Maintenance Request! We will Contact you shortly. ';
}
else {
    echo "This ($email2) email address is different from ($email1).\n";
}

There's no need to call filter_var() on $email2. If it's equal to $email1 then it must be valid. If it's not equal to $email1, we don't care if it's valid.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda