1

我在网络上创建了一个表单联系人,但是当我单击“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) );

?>

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

    });
});
4

3 回答 3

1

删除 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) 已打开

于 2013-10-28T15:36:35.350 回答
1

因为您提到内容类型设置标题是 text/json 可能您的浏览器配置为下载 json 而不是打开它。您可能需要JSONVIEW之类的插件才能在浏览器中查看它

于 2013-10-28T15:41:39.767 回答
0

出色地,

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

此外,您可能希望删除 @ 符号,正如 Amir 在他的帖子中指出的那样。

于 2013-10-28T15:37:43.177 回答