简体   繁体   English

表单错误-提交时单击会打开用于下载mail.php的窗口

[英]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. 我在网络上创建了一个表单联系人,但是当我单击“ Enviar”(提交按钮)时,表单电子邮件到达,但它打开一个窗口来下载mail.php,而不显示真实的表单结果。 where is the error? 错误在哪里? You can see it live in here: http://omgphotobooth.com.ar/jonetsugroup/contacto.php 您可以在此处实时查看它: 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: 这是使它工作的mail.php:

<?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. 这是表格的js。

$(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 在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 还要检查您的php.ini,并确保SMTP正常运行并且所需的端口(25)已打开

because you mention conent-type set the header is text/json maybe your browser is configured to download json instead of opening it. 因为您提到了conent-type设置,标题是text / json,也许您的浏览器配置为下载json而不是打开它。 You might need a plugin such as JSONVIEW to see it in your browser 您可能需要一个JSONVIEW之类的插件才能在浏览器中查看它

Well, 好,

One problem I see is that in the code that's visible you aren't including the jQuery library in your code. 我看到的一个问题是,在可见的代码中,您的代码中没有包含jQuery库。 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. 另外,您可能希望删除@符号,就像Amir在其帖子中指出的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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