繁体   English   中英

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

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

我在网络上创建了一个表单联系人,但是当我单击“ Enviar”(提交按钮)时,表单电子邮件到达,但它打开一个窗口来下载mail.php,而不显示真实的表单结果。 错误在哪里? 您可以在此处实时查看它: http : //omgphotobooth.com.ar/jonetsugroup/contacto.php

这是以下形式的网络代码:

<!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>

这是使它工作的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) );

?>

这是表格的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;
        }

    });
});

在mail.php中删除@

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

/

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

还要检查您的php.ini,并确保SMTP正常运行并且所需的端口(25)已打开

因为您提到了conent-type设置,标题是text / json,也许您的浏览器配置为下载json而不是打开它。 您可能需要一个JSONVIEW之类的插件才能在浏览器中查看它

好,

我看到的一个问题是,在可见的代码中,您的代码中没有包含jQuery库。 尝试先将其添加到您的代码中,然后看它如何工作。

另外,您可能希望删除@符号,就像Amir在其帖子中指出的那样。

暂无
暂无

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

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