将表单发送到电子邮件。 (AJAX,Bootstrap,Jquery)

时间:2015-10-19 09:30:04

标签: javascript php ajax

请帮我发电子邮件表格。 请帮助表单发送电子邮件。始终出现错误:您没有填写该字段。 即便是这个想法也不知道它可能是一个错误。 谢谢! 腓:

if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['tel'])&&$_POST['tel']!="")){ 
    $to = 'divanya@bk.ru'; // my email
    $subject = 'Обратный звонок'; // massage tiitle
    $message = '
            <html>
                <head>
                    <title>'.$subject.'</title>
                </head>
                <body>
                    <p>Name: '.$_POST['name'].'</p>
                    <p>Phone: '.$_POST['tel'].'</p>                        
                </body>
            </html>'; 
    $headers  = "Content-type: text/html; charset=utf-8 \r\n"; 
    $headers .= "From: sender <from@example.com>\r\n"; 
    mail($to, $subject, $message, $headers); 

}

HTML:

 <div id="popup11" class="popup11" >
    <div id="btn-close" class="f-close"> </div>
    <div class="header">Phone me</div>
    <div class="p1_msg">

    </div>
    <input class="pop_name1" type="text" value='Your name' onclick="if ($('.pop_name1').val()=='Your name'){ $('.pop_name1').val('');} $('.pop_name1').css('color','#000000');" >
    <input class="pop_tel1" type="text" value='Phone' onclick="if ($('.pop_tel1').val()=='Your phone'){ $('.pop_tel1').val('');} $('.pop_tel1').css('color','#000000');" >
    <a  id="callback-send11" class="btn b_red" onclick="goalEvent('order_success');">Send</a>

</div>




<div id="spasibo" class="spasibo" >
    <div class="header">Thanks!</div>
    <div class="p1_msg">
        Form send.
    </div>

    <a  id="callback-spasibo" class="btn b_red">Close</a>

</div>

JS:

            $(function() {
            $('#callback-send11').click(function(){

                var name=$('.pop_name1').val();
                var tel=$('.pop_tel1').val();

                if(!name.length || name == 'Your name' || !tel.length || tel == 'Your phone'){
                    alert ('You incorrectly filled field.');
                    return false;
                } else {

                    $.ajax({
                        type: "POST",
                        url: "forms.php",
                        data: "name="+name+"&tel="+tel+'&f=popup11',
                        success: function(data){
                            if (data=='ok'){
                                //alert ('Application successfully submitted');
                                $('#popup11').fadeOut(300);
                                $('.pop_name1').val('');
                                $('.pop_tel1').val('');
                                $('#spasibo').fadeIn(300);
                            }else{
                                alert ('You incorrectly filled field.');
                            };
                        }
                     });
                }
            });

0 个答案:

没有答案