Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda