2016-11-09 142 views
-3

我是HTML和PHP編程的新手。 當我從表單提交數據$ POST不是從表單獲取值,只是空值正在郵寄.spent相當多的時間,但無法想出它。

以下是代碼的一部分下面我的HTML表單

<form id="main-contact-form" class="contact-form" name="contact-form" method="POST" action="sendemail.php"> 
          <div class="form-group"> 
           <input type="text" name="namefirst" class="form-control" required="required" placeholder="Name"> 
          </div> 
          <div class="form-group"> 
           <input type="email" name="emailfirst" class="form-control" placeholder="Email ID"> 
          </div> 
          <div class="form-group"> 
          <input type="tel" name="tel" class="form-control" placeholder="Mobile No"> 
          </div> 

          <div class="form-group"> 
           <button type="submit" class="btn btn-primary pull-right">Send</button> 
          </div> 
         </form> 

的是我的PHP代碼

<?php 
header('Content-type: application/json'); 
$status = array(
    'type'=>'success', 
    'message'=>'Thank you for registering wth us.We will keep updating you.' 
); 

{ 
$name = $_POST["namefirst"]; 
$email = @trim(stripslashes($_POST["emailfirst"])); 

$email_from = $email; 
$email_to = '****';//replace with your email 

$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" ; 

$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>'); 

echo json_encode($status); 
} 

?> 

我已經嘗試了所有可能的解決方案,但它只是不working.Please讓我知道什麼是錯。

+0

看起來你的代碼有語法錯誤。請注意,如果沒有if語句或什麼的話,{{'應該做什麼。 – Maximus2012

+1

請發佈您的實際代碼。這不可能正確運行。 – TheValyreanGroup

+2

抑制錯誤'@'實際上不會幫助您排除它。 – Qirel

回答

0

我想明白了..問題不在於PHP或HTML文件它是與JavaScript代碼,值沒有設置在那裏@MueyiwaMosesIkomi非常感謝becoz這個我得到這個問題,所以解決這個問題我做了以下事情: EARLIER我的代碼是:

var form = $('.contact-form'); 
form.submit(function() {'use strict', 
    $this = $(this); 
    $.post($(this).attr('action'), function(data) { 
     $this.prev().text(data.message).fadeIn().delay(3000).fadeOut(); 
    },'json'); 
    return false; 
}); 

它沒有發送值。在這個代碼之後它的工作;

var form = $('.contact-form'); 
    var namefirst= $('.contact-form' . 'namefirst').val(); 
form.submit(function() {'use strict', 
    $this = $(this); 
      $.post($(this).attr('action'), function(data) { 
      $this.prev().text(data.message).fadeIn().delay(3000).fadeOut(); 
    },'json'); 
    return false; 
}); 

現在它發送值,但它會在下一個頁面上,並顯示PHP的回聲,因爲它是沒有編碼的Json,所以我thnik

$this.prev().text(data.message).fadeIn().delay(3000).fadeOut(); 
    },'json'); 

這部分代碼是不工作...能任何人對此有幫助??????

感謝你們所有人