PHP表单发送带有字段标题的电子邮件,没有收集的数据

时间:2012-01-28 22:16:53

标签: php forms

我一直试图让Php脚本在一周的大部分时间里工作: - /。我保持它非常简单,我似乎仍然无法想象这个......奇怪的是...... 它运行良好,我收到的电子邮件中包含以下消息:

Name:
Phone number:
Email Address :
Street Address:
Managment Contact:

正如你所看到的那样 - 虽然没有数据通过我。

这是HTML表单:

<td width="487" height="240" bgcolor="#1D1D1D"><form action="Contact form/processrequest.php" method="post" name="request form" target="_parent" id="request form">
              <table width="488" border="0" cellspacing="0" cellpadding="6">
                <tr>
                  <td width="161" height="34" align="right"><label for="name" class="adf">Name </label></td>
                  <td width="303" align="left" bgcolor="#1D1D1D"><input name="Name" type="text" id="Name" size="50" maxlength="200" /></td>
                </tr>
                <tr>
                  <td height="34" align="right" class="adf"><label for="phone">Phone Number </label></td>
                  <td align="left"><input name="Phone Number " type="text" id="Phone Number " size="50" maxlength="300" /></td>
                </tr>
                <tr>
                  <td height="34" align="right" class="adf"><label for="email">Email Address </label></td>
                  <td align="left"><input name="Email Address" type="text" id="Email Address" size="50" maxlength="300" /></td>
                </tr>
                <tr>
                  <td height="34" align="right" class="adf"><label for="street">Street Address </label></td>
                  <td align="left"><input name="Street Address" type="text" id="Street Address" size="50" maxlength="300" /></td>
                </tr>
                <tr>
                  <td height="34" align="right" class="adf"><label for="mgmt">MGMT Contact </label></td>
                  <td align="left"><input name="Management Contact" type="text" id="Management Contact" size="50" maxlength="300" /></td>
                </tr>
                <tr>
                  <td height="36" align="right">&nbsp;</td>
                  <td align="left"><input type="submit" name="Send" id="Send" value="Submit" /></td>

,这是PHP:

<?php
// Get Data 
$name= "$name";
$phone= "$phone";
$email= "$email";
$street= "$street";
$mgmt= "$mgmt";

// Send Message
mail( "myemail@my.com", "Contact From Website",
    "Name: $name \nPhone number: $phone \nEmail Address : $email\nStreet Address:              $street\nManagment Contact: $MGMT\n",
    "From: Wearable Collections Facebook App Bin Request Form  <myemail@my.com>" );
    ?>

我觉得我可能错过了一些非常明显的东西---所以任何帮助都会非常感激!!!!

2 个答案:

答案 0 :(得分:1)

问题在于:

$name= "$name";

要获取表单数据,您应该使用:

$name = $_POST['name'];

对每个表单字段重复一遍,您将拥有一组可用的数据。

答案 1 :(得分:1)

这就是你获取数据的方式。

尝试如下。

另外,请参阅下面的安全说明。

<?php
    // Get Data 
    $name= $_REQUEST["name"]; // Works for both get and post, as opposed to $_GET["name"] or $_POST["name"];
    $phone= $_REQUEST["phone"];
    $email= $_REQUEST["email"];
    $street= $_REQUEST["street"];
    $mgmt= $_REQUEST["mgmt"];

    // Send Message
    mail( "myemail@my.com", "Contact From Website",
    "Name: $name \nPhone number: $phone \nEmail Address : $email\nStreet Address:              $street\nManagment Contact: $MGMT\n",
    "From: Wearable Collections Facebook App Bin Request Form  <myemail@my.com>" );
    ?>

有关在此处使用PHP和Forms的更多信息:

http://php.net/manual/en/tutorial.forms.php

更多关于$ _REQUEST:

http://www.php.net/manual/en/reserved.variables.php

重要!!!!!另请参阅这些有关安全性的文章,您应该与表单处理一起学习:

http://phpsense.com/2006/php-email-injection-attacks/

http://www.sitepoint.com/php-security-blunders/

http://php.net/manual/fr/function.mysql-real-escape-string.php