获取有关邮件ID的用户信息

时间:2017-07-12 07:10:50

标签: php html5

我正在尝试通过“ mail()”功能在我的邮件ID上获取“注册用户信息”.mail()函数工作正常,可以通过邮件发送邮件id,但无法获取用户详细信息。 这是我的HTML代码:

   <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: XYZ@gmail.com";
$to = "XYZ@gmail.com"; 
$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");

提前致谢。

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

表单中缺少

method。你需要添加它。方法定义您是将值发送为GET还是POST。

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

答案 2 :(得分:0)

添加第一行method="post"

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