Php Ajax联系人表单未发送电子邮件

Php Ajax联系人表单未发送电子邮件,php,jquery,ajax,email,Php,Jquery,Ajax,Email,我正在使用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 shak

我正在使用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;
    }
});
jQuery(文档).ready(函数(){
//注释或取消注释所需的结果。
//当前,启用了“错误时抖动”。
//当一个字段留空时,jQuery将震动表单
/*开始配置*/
//var shake=“是”;
var=“否”;
/*结束配置*/
$(“#消息”).hide();
//添加验证部分
$(“#联系人输入[type=text]、#联系人输入[type=number]、#联系人输入[type=email]、#联系人输入[type=url]、#联系人输入[type=tel]、#联系人选择、#联系人文本区”)。每个(函数(){
$(本)。在('')之后;
});
//键入时进行验证
$('#email').focusout(函数(){
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');
});
$(“#提交”)。单击(函数(){
$(“#消息”).slideUp(200,函数(){
$(“#消息”).hide();
//启动验证
$(“#email”).triggerHandler(“focusout”);
if($('#contact mark.error').size()>0){
如果(摇晃=“是”){
$(“#接触”)。效果('shake'{
次数:2次
},75,函数(){
$('#contact input.error:first,#contact textarea.error:first').focus();
});
}else$('#contact input.error:first,#contact textarea.error:first').focus();
返回false;
}
});
});
$('#contactform')。提交(函数(){
if($('#contact mark.error').size()>0){
如果(摇晃=“是”){
$(“#接触”)。效果('shake'{
次数:2次
}, 75);
}
返回false;
}
var action=$(this.attr('action');
$(“#提交”)
.在(“”)之后
.attr(“禁用”、“禁用”);
$员额(行动{
名称:$('#name').val(),
电子邮件:$('#email').val(),
电话:$(“#电话”).val(),
网站:$(“#网站”).val(),
kvk:$('#kvk').val(),
发送:$(“#发送”).val(),
webwinkel:$('#webwinkel').val(),
帕克滕:$('#帕克滕').val(),
},
功能(数据){
$('#message').html(数据);
$(“#消息”).slideDown();
$('#contactform img.loader').fadeOut('slow',function(){
$(this.remove())
});
$('contactform'submits').attr('disabled','');
if(data.match('success')!=null)$('contactform').slideUp('slow');
});
返回false;
});
功能isEmail(电子邮件地址){
(2)目前(以下以下::::::::[[[[w-[w-[[w-[[[w-[[[w-[[[w-[[[w-]+)*)))除了除了除了上述两个新的RegExp((((((“[[[[[w-\w-\w-\s][[[[[[3-\s-\s[s-\s[s-[s][[[[[s][[[3]]]]]的)的)的)号号号))))))))在目前,((((((((((()))))目前((([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[|[0-9]{1,2}\)((25[0-5]{2[0-4][0-9]{2}{0-9]{1,2}\){2}(25[0-5]{2[0-4][0-9]{1[0-9]{2}{1,2}}})/);
返回模式.test(emailAddress);
}
函数为数字(输入){
返回值(输入-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!';

     }

}
 ?>

在这么多层面上有这么多错误,请先看看www.phptherightway.com


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

JavaScript有布尔变量的概念,没有理由将存储true或false值的变量设置为“Yes”或“no”.服务器端代码在哪里?如果脚本在“其他”上运行,Javascript不会发送任何邮件站点,您当前的服务器配置或服务器端代码可能有一个特定问题。如果没有服务器端代码,则无法对其进行分析,因为服务器端代码实际上会发送电子邮件。JavaScript不会发送电子邮件。您需要通过一些基本调试来缩小问题的范围。此脚本如何告诉其他系统发送电子邮件?其他系统是否系统接收到它需要的数据?(例如,您可以在浏览器调试工具(如FireBug或Chrome developer工具)中监视HTTP POST值。)代码具体在哪里失败?发生这种情况时的运行时值是什么?目前您的问题无法回答。“我复制并粘贴了一些代码,但其他事情没有发生”这不是一个问题。
$('#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;

});