简体   繁体   中英

Form error - at submit click opens the window for downloading mail.php

I create a form contact on a web, but when I click on "Enviar" (the submit button) the form email arrives but it opens a window to download the mail.php instead of showing the true form result. where is the error? You can see it live in here: http://omgphotobooth.com.ar/jonetsugroup/contacto.php

this is the web code of the form:

<!doctype html>
<html>
<head>
<script type="text/javascript" src="formValidar/formValidar.js"></script>
</head>
<body>
        <div class="formulario">
           <!--form-->
           <form id="web" method="POST" action="mail.php">
            <div class="campos">     
                <div class="caja">
                    <div class="flecha"></div>
                    <label class="tituloform" for="nombre">Nombre Completo
                    <span class="asterisk">*</span>
                    </label>
                    <input name="nombre" class="ss-q-short" id="formNombre" type="text">
                </div>
                <div class="caja">
                    <div class="flecha"></div>
                    <label class="tituloform" for="telefono">Teléfono
                    <span class="asterisk"></span>
                    </label>
                    <input name="telefono" class="ss-q-short" id="formTelefono" type="number">
                </div>
                <div class="caja">
                    <div class="flecha"></div>
                    <label class="tituloform" for="email">Mail
                    <span class="asterisk">*</span>
                    </label>
                    <input name="email" class="ss-q-short" id="formEmail" type="email">
                </div>
                <div class="caja">
                    <div class="flecha"></div>
                    <label class="tituloform" for="email">Fecha de Evento
                    <span class="asterisk"></span>
                    </label>
                    <input name="fecha" class="ss-q-short" id="formFecha" type="text">
                </div>
                <div class="caja">
                    <div class="flecha"></div>
                    <label class="tituloform" for="asunto">Asunto
                    </label>
                    <input name="asunto" class="ss-q-short" id="formAsunto" type="text">
                </div>
                </div>
                <div class="punteadolargo" id="contacto"></div>
              <div class="raya" id="contacto"></div>
                <img src="img/mensaje.jpg" class="mensajecinta">
              <div class="mensaje">
              <div class="caja">
                    <label class="tituloform" for="mensaje">
                    </label>
                    <textarea name="mensaje" class="ss-q-short" id="formMensaje" form="web"></textarea>
                </div>
                </div>
            <div id="webFormResult"></div>
            <div>
                <p style="text-align:center">
                <input type="submit" value="" class="submit" name"submit"/>
                </p>
            </div>
        </form>
            <script type="text/javascript" src="global.js"></script>

        <!--form-->
        </div>
</body>
</html>

this is the mail.php that make it work:

<?php

$header = 'From: info@omgphotobooth.com.ar' . "\r\n" .
'Reply-To: '.$_POST["email"]. "\r\n" .
'X-Mailer: PHP/' . phpversion();

$msg = '';

foreach($_POST as $k => $v) {
    $msg .= "$k: $v \n";
}

$res = @mail('maiamaranghello@gmail.com', 'Contacto desde web', $msg, $header);

header('Content-type: text/json');


$res = true;

echo json_encode( array('result' => $res) );

?>

this is de js for the form.

$(document).ready(function(){

    $('form#web').submit(function(){

        var definitions = [
        {
            id: 'formNombre',
            type: 'string',
            title: 'nombre'
        },

        {
            id: 'formEmail',
            type: 'email',
            title: 'email'
        },

        {
            id: 'formAsunto',
            type: 'string',
            title: 'asunto'
        },
        {
            id: 'formMensaje',
            type: 'string',
            title: 'mensaje'
        }       
        ];

        if( formValidar($(this), definitions) ) {

            console.log($(this));

            $.post('mail.php', $(this).serialize(), function(json){

                if(json.result == true) {
                    $('#webFormResult').html('El mensaje se ha enviado correctamente!');
                } else {
                    $('#webFormResult').html('No pudimos enviar el mensaje, intente nuevamente');
                }
                $("#web input[type=text],#web input[type=email], #web input[type=number], #web textarea, #web select").val('');

            });

            return false;

        } else {
            return false;
        }

    });
});

remove @ in mail.php

$res = @mail('maiamaranghello@gmail.com', 'Contacto desde web', $msg, $header);

/

$res = mail('maiamaranghello@gmail.com', 'Contacto desde web', $msg, $header);

also check you php.ini and make sure SMTP is working fine and required port (25) is open

because you mention conent-type set the header is text/json maybe your browser is configured to download json instead of opening it. You might need a plugin such as JSONVIEW to see it in your browser

Well,

One problem I see is that in the code that's visible you aren't including the jQuery library in your code. Try adding that to your code first and see how it works.

Also, you might want to remove the @ symbol as Amir noted in his post.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM