添加更多输入字段时,html / php表格会给我500个内部服务器错误 [英] html/php form gives me 500 internal server error when adding more input fields

查看:150
本文介绍了添加更多输入字段时,html / php表格会给我500个内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的php和html表单有问题。我想要做的只是获得一个带有7个输入字段的表单,其中6个是输入字段或文本区域,其中一个将是复选框。我有一个隐藏字段,前3个字段隐藏字段的名字和消息。我遇到的唯一问题是当我添加一个新的输入框时,它显示了500错误。我的代码如下:

Hi, I have a problem with my php and html form. What I am trying to do is just get a form with 7 input fields, 6 of these are input field or text area and one will be a checkbox. I have one hidden field, the first 3 boxes the hidden field the first name and message. The only problem I have is when I add a new input box it shows me the 500 error. My code is below:

<?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";

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

When I add a new input box my code looks like :

<?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";

当我添加它们时,屏幕上会显示所有内容,但是当我按提交时,我会得到:

Everything shows on the screen when I add them but when I press submit I get:


500 - 内部服务器错误。您的
所寻找的资源存在问题,并且无法显示。

500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed.

并且没有提交。是因为它在发送之前超时,或者有很多数据,或者我错过了一些非常基本的东西?

and nothing gets submitted. Is it because it times out before it send or to much data or have I just missed something very basic?

任何帮助都将非常感谢。

Any help would be much appreciated.

推荐答案

6变量将导致:

警告:mail()期望最多5个参数,网上线上

解决方案示例:

Solution example:

    <?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:

Answer to your reply:
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>

演示: here

它会将邮件发送到您输入的邮件中

Demo: here
It will send the mail to the mail your entered in the form

这篇关于添加更多输入字段时,html / php表格会给我500个内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆