2014-04-21 3 views
0

이 양식을 얻기 위해 모든 노력을했지만 운이 없었습니다.abide - php가있는 재단 문의 양식이 작동하지 않습니다.

나는 지금 일하고 있다고 생각하지만 지금은 작동하지만 내 PHP는 이메일을 보내지 않고있다. 나는 심지어 내 PHP가 어쨌든 호출되고 있다고 생각하지 않습니다.

내 코드

형태 코드 선 아래 434

<form id="myForm" data-abide action="mail.php" method="post"> 
           <div class="contactform"> 
            <div class="item item-pair"> 
             <label for="name">Full Name 
             <input type="text" name="name" id="name" class="small-input cat_textbox" required pattern="[a-zA-Z]+" maxlength="255"> 
             <small class="error small-input">Name is required and must be a string.</small> 
             </label> 
             <label for="email">Email Address 
             <input type="text" name="email" id="email" class="small-input cat_textbox" maxlength="255" required > 
             <small class="error small-input">An email address is required.</small> 
             </label> 
            </div> 
            <div class="item"> 
             <label>Comments</label> 
             <textarea cols="10" name="message" id="message" rows="4" class="cat_listbox" required ></textarea> 
             <small class="error">Please enter your comments</small> 
            </div> 
            <div class="item"> 
             <input class="button alert small" type="submit" value="Submit" id="catwebformbutton"> 
            </div> 
           </div> 
           </form> 

자바 스크립트 코드 라인 (627)

<script> 

     $('#myForm').submit(function(e) { 
      //prevent default form submitting. 
      e.preventDefault(); 

      $(this).on('valid', function() { 
       var name = $("input#name").val(); 
       var email = $("input#email").val(); 
       var message = $("textarea#message").val(); 

       //Data for reponse 
       var dataString = 'name=' + name + 
       '&email=' + email + 
       '&message=' + message; 

       //Begin Ajax call 
       $.ajax({ 
       type: "POST", 
       url:"mail.php", 
       data: dataString, 
       success: function(data){ 
        $('.contactform').html("<div id='thanks'></div>"); 
        $('#thanks').html("<h2>Thanks!</h2>") 
        .append("<p>Dear "+ name +", I will get back to you as soon as I can ;)</p>") 
        .hide() 
        .fadeIn(1500); 
       }, 
       }); //ajax call 
       return false; 
      }); 
      });  


     </script> 

HTML 링크 http://tayrani.com

하십시오이다 도움

<?php 

$name = $_POST["name"]; 
$email = $_POST["email"]; 
$comments = $_POST["message"]; 

$msg = " 
Name:$name 
Email:$email 
Comment: 
$comments"; 

$to = "[email protected]"; 
$subject = "website email"; 
$message = $msg; 
$headers = "form"; 
mail($to,$subject,$message,$headers); 

?> 
+0

당신의 AJAX 기능이 잘 작동되어

감사합니다,

후세인 ..? var_dump ($ name);을 넣으십시오. mail.php에서 $ name이 (가) 값을 얻고 있는지 찾습니다. – shashank

+0

그냥 아약스 호출이 작동하는지 확인하고 싶습니다. var_dump ($ name); mail.php 페이지에서 다시 시도하십시오. 그래서 우리는 실제 문제를 발견 할 수 있습니다. – shashank

+0

내가 거기에 넣었지만 아무 것도하지 않았다. 특정 작업을 수행해야합니까? –

답변

0

도움을 주셔서 감사합니다. 그것은 어떤 이유로 이메일을받지 못하는 Hotmail로 밝혀졌습니다. 그래서 Hotmail 계정을 Gmail 계정으로 바꿨습니다. 또한 형태에 대해 다음

HTML 코드 내 코드를 업데이트

여기 '

<script> 
$('#myForm').submit(function(e) { 
    //prevent default form submitting so it can run the ajax code first 
    e.preventDefault(); 

    $(this).on('valid', function() { //if the form is valid then grab the values of these IDs (name, email, message) 
     var name = $("input#name").val(); 
     var email = $("input#email").val(); 
     var message = $("textarea#message").val(); 

     //Data for reponse (store the values here) 
     var dataString = 'name=' + name + 
     '&email=' + email + 
     '&message=' + message; 

     //Begin Ajax call 
     $.ajax({ 
     type: "POST", 
     url:"mail.php", //runs the php code 
     data: dataString, //stores the data to be passed 
     success: function(data){ // if success then generate the div and append the the following 
      $('.contactform').html("<div id='thanks'></div>"); 

      $('#thanks').html("<br /><h4>Thanks!</h4>") 
      .append('<p><span style="font-size:1.5em;">Hey</span> <span class="fancy">'+ name +'</span>,<br />I&acute;ll get back to you as soon as I can ;)</p>') 
      .hide() 
      .fadeIn(1500); 
     }, 
     error: function(jqXHR, status, error){ //this is to check if there is any error 
      alert("status: " + status + " message: " + error); 
     } 
     }); //End Ajax call 
     //return false; 
    }); 
    });  
</script> 

<script> 
    $(document).foundation('abide', 'events'); // this was originally before the above code, but that makes the javascript code runs twice before submitting. Moved after and that fixes it. 
</script> 

를 발급 두 번 제출 고정을 포함하여 내 자바 스크립트 코드는 PHP 코드

<?php 

if(isset($_POST["name"])){ 
    $name = $_POST["name"]; 
    $email = $_POST["email"]; 
    $comments = $_POST["message"]; 

    $msg = " 
    Name: $name 
    Email: $email 
    Comments: 
    $comments"; 

    $to = "[email protected]"; 
    $subject = "Tayrani.com Contact Form"; 
    $headers = "From: <$email>"; 

    mail($to,$subject,$msg,$headers); 
}else{ 

} 
?> 
에게 있습니다
<form id="myForm" data-abide="ajax" action="mail.php" method="post"> 
    <div class="contactform"> 
     <div class="item item-pair"> 
      <label for="name">Full Name 
      <input type="text" name="name" id="name" class="small-input cat_textbox" required pattern="[a-zA-Z]+" maxlength="255"> 
      <small class="error small-input">Name is required and must be a string.</small> 
      </label> 
      <label for="email">Email Address 
      <input type="email" name="email" id="email" class="small-input cat_textbox" maxlength="255" required > 
      <small class="error small-input">An email address is required.</small> 
      </label> 
     </div> 
     <div class="item"> 
      <label>Comments</label> 
      <textarea cols="10" name="message" id="message" rows="4" class="cat_listbox" required ></textarea> 
      <small class="error">Please enter your comments</small> 
     </div> 
     <div class="item"> 
      <input class="button alert small" type="submit" value="Submit" id="catwebformbutton" name="btnSubmit"> 
     </div> 
    </div> 
</form> 

나는 이것을 끝내기 위해 3 일 동안 고생했다. 그러나 나의 동료/친구 Adam에게 감사한다 그것으로 정말로 나를 도왔다.

다른 사람에게 유용하기를 바랍니다. tayrani.com

관련 문제