增加更多的输入字段时,HTML / PHP的形式给了我500内部服务器错误(html/php for

2019-10-30 03:27发布

嗨,我有我的PHP和HTML表单的一个问题。 我所试图做的只是得到一个表格7个输入字段,这些6输入字段或文本区域和一个将是一个复选框。 我有一个隐藏字段,第3盒隐藏字段的名字和信息。 我唯一的问题是,当我添加一个新的输入框,它让我看到500错误。 我的代码如下:

<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
  {
  ?>

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

  <input type="hidden" name="subject" value="can you create me an account"><br>
  Message: <textarea rows="10" cols="40" name="message"></textarea><br>
  first <input type="text" name="first_name" >
  <input type="submit" name="submit" value="Submit Feedback">
  </form>

<?php 
  }
else
  // the user has submitted the form
  {
  // Check if the "subject" input field is filled out
  if (isset($_POST["subject"]))
    {
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $first = $_POST["first_name"];


    $message = wordwrap($message, 70);
    $first = wordwrap($first, 70);
    // send mail
    mail("summat@gmail.com",$subject,$message,$first,"subject: $subject\n");
    echo "Thank you for sending us feedback";

当我添加一个新的输入框,我的代码如下所示:

<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
  {
  ?>

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

   <input type="hidden" name="subject" value="can you create me an account"><br>
   Message: <textarea rows="10" cols="40" name="message"></textarea><br>
   first <input type="text" name="first_name" >
   last <input type="text" name="last_name" >
   <input type="submit" name="submit" value="Submit Feedback">
  </form>

<?php 
  }
else
  // the user has submitted the form
  {
  // Check if the "subject" input field is filled out
  if (isset($_POST["subject"]))
    {
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $first = $_POST["first_name"];
    $last = $_POST["last_name"];


    $message = wordwrap($message, 70);
    $first = wordwrap($first, 70);
    $last = wordwrap($last, 70);
    // send mail
    mail("summat@gmail.com",$subject,$message,$first,$last,"subject: $subject\n");
    echo "Thank you for sending us feedback";

一切都显示,当我加入他们,但是当我按下提交我得到的屏幕上:

500内部服务器错误。 有一个与你正在寻找的资源问题,它无法显示。

并没有什么被提交。 是不是因为它超时之前它发送或大量数据或有我只是错过了一些非常基本的?

任何帮助将非常感激。

Answer 1:

6个变量将导致:
警告:电子邮件()预计最多5个参数,在您的在线网站给出6

解决方案示例:

    <?php
     //var_dump($_POST);
    if (isset($_POST["subject"]))
        {
        $subject = $_POST["subject"];
        $message = $_POST["message"];
        $first = $_POST["first_name"];
        $last = $_POST["last_name"];
        $name= "$first $last";
    }
        $message = wordwrap($message, 70);
        $first = wordwrap($first, 70);
        $last = wordwrap($last, 70);
        mail("summat@gmail.com",$subject,$message,$name,"subject: $subject\n");
        echo "Thank you for sending us feedback";
      ?>

回答您的回复:
PHP的:

 <?php
 //var_dump($_POST);
if (isset($_POST["subject"]))
    {
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    $first = $_POST["first_name"];
    $last = $_POST["last_name"];
    $company = $_POST["company"];
    $email = $_POST["email"];
    $telnr = $_POST["telnr"];
    $description = $_POST["description"];
    $therest = "First name= $first" . "\r\n" . "Last name= $last" . "\r\n" . "Last name= $last" . "\r\n" . "Company= $company" . "\r\n" . "Email= $email" . "\r\n" . "Telnr= $telnr" . "\r\n" . "Description= $description";          

    //echo "$therest <br>";
    $message = wordwrap($message, 70);
    $first = wordwrap($first, 70);
    $last = wordwrap($last, 70);
    mail("Your Email Address Here",$subject,$name,$therest,"subject: $subject\n");
    echo "Thank you for sending us feedback";
}

HTML

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

   <input type="hidden" name="subject" value="can you create me an account"><br>
   Message: <textarea rows="10" cols="40" name="message"></textarea><br>
   first <input type="text" name="first_name" ><br>
   last <input type="text" name="last_name" ><br>
   company <input type="text" name="company" ><br>
   email <input type="text" name="email" ><br>
   Telephone number <input type="text" name="telnr" ><br>
   Description <input type="text" name="description" ><br>
   <input type="submit" name="submit" value="Submit Feedback">
  </form>

演示: 在这里
这将邮件发送到您的邮件在表单中输入



Answer 2:

问题是,在第二个例子中,你正在试图通过6个变量的mail()函数时,它接受5.检查在这里你可以如何通过附加头。



文章来源: html/php form gives me 500 internal server error when adding more input fields