-1

我正在使用 ajax 联系表:

jQuery(document).ready(function () {
    // Comment or uncomment the result you want.
    // Currently, shake on error is enabled.
    // When a field is left blank, jQuery will shake the form

    /* Begin config */

    //  var shake = "Yes";
    var shake = "No";

    /* End config */

    $('#message').hide();

    // Add validation parts
    $('#contact input[type=text], #contact input[type=number], #contact input[type=email], #contact input[type=url], #contact input[type=tel], #contact select, #contact textarea').each(function () {
        $(this).after('<mark class="validate"></mark>');
    });

    // Validate as you type
    $('#email').focusout(function () {
        if (!$(this).val() || !isEmail($(this).val())) $(this).addClass('error').parent().find('mark').removeClass('valid').addClass('error');
        else $(this).removeClass('error').parent().find('mark').removeClass('error').addClass('valid');
    });

    $('#submits').click(function () {
        $("#message").slideUp(200, function () {
            $('#message').hide();

            // Kick in Validation
            $('#email').triggerHandler("focusout");

            if ($('#contact mark.error').size() > 0) {
                if (shake == "Yes") {
                    $('#contact').effect('shake', {
                        times: 2
                    }, 75, function () {
                        $('#contact input.error:first, #contact textarea.error:first').focus();
                    });
                } else $('#contact input.error:first, #contact textarea.error:first').focus();

                return false;
            }

        });
    });

    $('#contactform').submit(function () {

        if ($('#contact mark.error').size() > 0) {
            if (shake == "Yes") {
                $('#contact').effect('shake', {
                    times: 2
                }, 75);
            }
            return false;
        }

        var action = $(this).attr('action');

        $('#submits')
            .after('<img src="/system/cms/themes/default/views/partials/assets/ajax-loader.gif" class="loader" />')
            .attr('disabled', 'disabled');

        $.post(action, {
            name: $('#name').val(),
            email: $('#email').val(),
            phone: $('#phone').val(),
            website: $('#website').val(),
            kvk: $('#kvk').val(),
            sending: $('#sending').val(),
            webwinkel: $('#webwinkel').val(),
            pakketten: $('#pakketten').val(),
        },

        function (data) {
            $('#message').html(data);
            $('#message').slideDown();
            $('#contactform img.loader').fadeOut('slow', function () {
                $(this).remove()
            });
            $('#contactform #submits').attr('disabled', '');
            if (data.match('success') != null) $('#contactform').slideUp('slow');

        });

        return false;

    });

    function isEmail(emailAddress) {

        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

        return pattern.test(emailAddress);
    }

    function isNumeric(input) {
        return (input - 0) == input && input.length > 0;
    }
});

在某种程度上,如果我排除此脚本,它不会发送电子邮件,电子邮件脚本是否有效?

我已经尝试了一切,但我无法让它工作,我认为这很奇怪,因为我在更多地方使用这个脚本并且它在那里工作:(...

任何人的想法?

* 更新邮件脚本 *

<?php if (!isset($_SESSION)) session_start();

if(!$_POST) exit();

    if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

    $name       = $_POST['name'];
    $email      = $_POST['email'];
    $phone      = $_POST['phone'];
    $website    = $_POST['website'];
    $kvk        = $_POST['kvk'];
    $sending    = $_POST['sending'];
    $webwinkel  = $_POST['webwinkel'];
    $pakketten  = $_POST['pakketten'];
    $error      = '';

    if (isset($_POST['verify'])) :
        $posted_verify   = $_POST['verify'];
        $posted_verify   = md5($posted_verify);
    else :
        $posted_verify = '';
    endif;

    // Important Variables
    $session_verify = $_SESSION['verify'];

    if (empty($session_verify)) $session_verify = $_COOKIE['verify'];



    if($error == '') {

    if(get_magic_quotes_gpc()) {
            $comments = stripslashes($comments);
        }

     // Configuration option.

     $address = "email@email.com";


     // Configuration option.
     // i.e. The standard subject will appear as, "You've been contacted by John Doe."

     // Example, $e_subject = '$name . ' has contacted you via Your Website.';

     $e_subject = 'Nieuwe Aanmelding';


     // Configuration option.
     // You can change this if you feel that you need to.
     // Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

     $e_body  = "Er is een nieuwe aanmelding binnen gekomen:\n\n" . PHP_EOL . PHP_EOL;
     $e_name  = "Name: $name \n\n";
     $e_email = "Email: $email \n\n";
     $e_phone = "Tel: $phone \n\n";
     $e_kvk   = "KVK: $kvk \n\n";
     $e_website   = "Website: $website \n\n";
     $e_sending = "Verzending nu: $sending \n\n";
     $e_winkel= "Webwinkel: $webwinkel \n\n";
     $e_pakketten= "Paketten per maand: $pakketten \n \n";

     $msg = wordwrap($e_body . $e_name . $e_email . $e_website  . $e_phone . $e_kvk . $e_sending . $e_winkel . $e_pakketten,70);

     $headers = "From: $email" . PHP_EOL;
     $headers .= "Reply-To: $email" . PHP_EOL;
     $headers .= "MIME-Version: 1.0" . PHP_EOL;
     $headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
     $headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

     if(mail($address, $e_subject, $msg, $headers)) {


     // Email has sent successfully, echo a success page.

     echo "<div class='span12'>";
     echo "<div class='span4'></div>";
     echo "<div class='span6'>";
     echo "<div id='success_page'>";
     echo "<h1 style='color:white'>Uw aanmelding is verzonden.</h1>";
     echo "<p style='color:white'>Bedankt <strong>$name</strong>, U wordt zo spoedig mogelijk geholpen.</p>";
     echo "</div>";
     echo "</div>";

     } else {

     echo 'ERROR!';

     }

}
 ?>

解决

伙计们,

感谢您及时的回复。

这是我刚刚下载的新 jquery,它现在可以工作了。

$('#contactform').submit(function(){

    if ($('#contact mark.error').size()>0) {
        if(shake == "Yes") {
        $('#contact').effect('shake', { times:2 }, 75);
        }
        return false;
    }

    var action = $(this).attr('action');

    $('#submit')
        .after('<img src="assets/img/ajax-loader.gif" class="loader" />')
        .attr('disabled','disabled');

    $.post(action, $('#contactform').serialize(),
        function(data){
            $('#message').html( data );
            $('#message').slideDown();
            $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
            $('#contactform #submit').removeAttr('disabled');
            if(data.match('success') != null) $('#contactform').slideUp('slow');

        }
    );

    return false;

});
4

1 回答 1

0

这么多层次有这么多错误,请先看看www.phptherightway.com。

之后,尝试确定表单是否正在发送到服务器(通过 POST 请求方法)。如果不是,我猜表单在提交事件中返回 false,这就是它最有可能无法正常工作的原因。

于 2013-11-06T13:43:21.007 回答