SELECT HTML tag

0

Excuse me what happens is that I am new to programming with php and I have a question, when validating a SELECT tag with php, what I want you to do is that the user at the moment of clicking on an option the mail to which will be sent by default change depending on the option that the user chooses, I need javascript or php forces just to call the option? this is my html code:

<form method="POST" action="contact.php" id="formulario" onSubmit="alert('Gracias por contactarnos, Nos comunicaremos contigo a la brevedad!');">
            <div class="form">
                <h2 class="formulario-letras text-center"><i class="fas fa-envelope"></i> Déjanos tu mensaje</h2>
                <h4 class="opciones-letras text-center">¿Qué desea hacer?</h4>
                <select name="opciones" id="opciones">
                    <option value="0" selected>Seleccione una opción</option>
                    <option value="1">Comentarios</option>
                    <option value="2" >Solicitar factura</option>
                </select>

and this my php code

<?php 

 $nombre= isset($_POST['name']) ? $_POST['name'] : '';
 $email = isset($_POST['email']) ? $_POST['email'] : '';
 $telefono = isset($_POST['telefono']) ? $_POST['telefono'] : '';
 $asunto = isset($_POST['asunto']) ? $_POST['asunto'] : '';
 $mensaje = isset($_POST['comment']) ? $_POST['comment'] : '';
 $contenido = '    

                    <html>
                        <head>          
                        </head>
                    <body>
                        <h2>Haz recibido un mensaje a través de la página</h2>
                        <p>'. $nombre .' te ha enviado el siguiente mensaje:</p>
                        <p>'. $mensaje .'<br><br> Puedes ponerte en contacto con la persona al email: '. $email .'</p>
                        <p>o al telefono: '. $telefono .'</p>
                        <hr>
                    </body>
                    </html>';


  //configuración de los encabezados

   $headers = 'MIME-Version: 1.0' . "\r\n";
   $headers .= "Content-type: text/html; charset=UTF-8\r\n";

   //Enviar correo
   $envio=mail('direcció[email protected]' ,$asunto, $contenido, 
   $headers);
   $envio2=mail('[email protected]', $asunto, $contenido, $headers);

   //Reseteo
   $msg = $tuSeleccion = NULL;

 //validar opciones
 if(isset($_POST['enviar'])){
 //selección obligatoria

if(empty($_POST['opciones'] [0])){
    $msg = 'Debes elegir una opción';
}

else{
    //obtenemos el dato del option seleccionado
    $tuSeleccion= $_POST['opciones'];
}



//Verdadero seleción

if(isset($_POST['opciones'] [1]))
{
    echo "yes";
}

else if(isset($_POST['opciones'] [2]))
{
    echo "no";
}
}

Help please is for a project

    
asked by Juan Angel Hdz 25.05.2018 в 19:41
source

1 answer

0

The value returned in $_POST["opciones"] contains the value selected by the user, you do not have to validate all. vast with using that value to decide which email to send in your php:

$opciones = $_POST['opciones'];
switch($opciones){
    case "0": email = "[email protected]";
    break;
    case "1": email = "[email protected]";
    break;
    case "2": email = "[email protected]";
    break;
    default: email = "[email protected]";
}
    
answered by 25.05.2018 / 19:54
source