Question

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 - 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.

Was it helpful?

Solution 2

6 Variables will result in:
Warning: mail() expects at most 5 parameters, 6 given in YOUR WEBSITE on LINE

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

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>

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

OTHER TIPS

The problem is that in the 2nd example you're trying to pass 6 variables to the mail() function when it accepts 5. Check here on how you can pass additional headers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top