2017-07-12 121 views
0

我試圖通過「mail()」函數在我的郵件ID上獲取「註冊用戶信息」。郵件()函數工作正常,並且能夠發送郵件郵件ID,但無法獲取用戶詳細信息。 這裏是我的HTML代碼:獲取郵件ID的用戶信息

<form action="registration.php" id="reg_form"> 
    <div class="form-msg alert with-icon alert-warning"> 
     <i class="fa fa-info-circle"></i> 
     <span id="text-login-msg"> 
      Put your valid Emai id and we will mail you the login details on your register id. 
     </span> 
     </div> 
     <div class="row"> 
     <div class="form-group col-md-12"> 
      <label> 
      Name<span class="red">*</span> 
      </label> 
      <input type="text" class="form-control" name="name" required> 
     </div> 
     </div> 
     <div class="row"> 
     <div class="form-group col-md-12"> 
      <label> 
      Email<span class="red">*</span> 
      </label> 
      <input type="email" class="form-control" name="email" required> 
     </div> 
     </div>         
     <div class="clearfix"></div>        
     <div class="button-group"> 
     <input type="submit" class="btn btn-lg main-bg btn-block" value="Submit"> 
     </div> 
    </form> 

這是我的PHP代碼:

$headers = "From: [email protected]"; 
$to = "[email protected]"; 
$Email = $_POST['email']; 
$Name = $_POST['name']; 
$subject = "Registration"; 
$email_message = "Form details below. \r\n"; 
$email_message .= "Name: ".$Name. "\r\n"; 
$email_message .= "Email: ".$Email. "\r\n"; 

mail ($to, $subject, $email_message, $headers); 
header("Location: thank-you.html"); 

在此先感謝。

回答

1

您需要指定method="POST"form,如:

<form action="registration.php" id="reg_form" method="POST"> 

的默認值是 「GET」。在這種情況下,您可以讀取這些輸入爲$_GET['name']$_GET['email']

請參閱此鏈接https://www.w3schools.com/tags/att_form_method.asp

+0

謝謝,它的工作,愚蠢的錯誤是在我身邊做。 – Shubham

0

method中缺少您的形式。你需要補充一點。方法定義您是否將值作爲GET或POST發送。

<form action="registration.php" id="reg_form" method='post'> 
+0

謝謝@Milan Chheda – Shubham

+0

不客氣。快樂編碼! –

0

添加在您的第一線method="post"

<form action="registration.php" id="reg_form" method="post"> 
+0

謝謝@雷虹 – Shubham