【问题标题】:PhP form not receiving inputsPhP 表单未接收输入
【发布时间】:2013-08-24 05:45:46
【问题描述】:

我创建了一个联系表单 contact.php ,它将值提交给 send_contact.php 并处理输入

但是发生了什么,在我点击提交按钮后,send_contact.php 文件会显示在浏览器中

contact.php

  <table width="300" border="0" align="left" cellpadding="0" cellspacing="1">
    <tr>
      <td>
        <form target="_blank" name="form1" method="post" action="send_contact.php" id="form1">
          <table width="100%" border="0" cellspacing="1" cellpadding="3">
            <tr>
              <td width="16%">Subject</td>

              <td width="2%">:</td>

              <td width="82%"><input name="subject" type="text" id="subject" size="30" /></td>
            </tr>

            <tr>
              <td>Detail</td>

              <td>:</td>

              <td>
              <textarea name="detail" cols="24" rows="4" id="detail">
              </textarea></td>
            </tr>

            <tr>
              <td>Name</td>

              <td>:</td>

              <td><input name="name" type="text" id="name" size="30" /></td>
            </tr>

            <tr>
              <td>Email</td>

              <td>:</td>

              <td><input name="customer_mail" type="text" id="customer_mail" size="30" /></td>
            </tr>

            <tr>
              <td></td>

              <td></td>

              <td><input type="submit" name="Submit" value="Submit" /><input type="reset" name="Submit2" value="Reset" /></td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
  </table>

send_contact.php

<?php

    // Contact subject
    $subject ="$subject"; 

    // Details
    $message="$detail";

    // Mail of sender
    $mail_from="$customer_mail"; 

    // From 
    $header="from: $name <$mail_from>";

    // Enter your email address
    $to ='abcd@gmail.com';
    $send_contact=mail($to,$subject,$message,$header);

    // Check, if message sent to your email 
    // display message "We've recived your information"
    if($send_contact){
    echo "We've recived your contact information";
    }
    else {
    echo "ERROR";
    }

?>

【问题讨论】:

  • 使用php开闭标签"",如果你用过短标签,你的服务器可能不支持。
  • 这是您的 send_contact.php 的完整代码,因为我没有看到打开的 php 标记 (

标签: php html forms email


【解决方案1】:

您似乎依赖于register globals,这是一个危险的 PHP 功能,已从该语言的最新版本中完全删除。

要访问从带有method="post" 的表单提交的数据,您需要使用the $_POST superglobal 数组。

$subject = $_POST['subject'];

【讨论】:

    【解决方案2】:

    你需要从$_POST中获取值,例如

    $subject ="$subject";
    

    应该是这样的:

    $subject =$_POST['subject'];
    

    这是您使用超全局数组 $_POST 从表单访问值的方式

    【讨论】:

      猜你喜欢
      • 2022-01-14
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多