Question

So I'm trying to make a very simple contact form which only submits one text field and when you submit it, the subject in the email you get from the form will be "add this" then in the message it will say what they submitted... How do I do this?

My form

   <form action="submit.php" method="post" name="contact_form">
      <input name="name" id="name" type="text">
      <input type="submit" name="submit" id="sumitbtn" value="submit">
   </form>

this is the form code i'm trying to copy but make my own version of it

<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"]))
  {
  ?>
  <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  From: <input type="text" name="from"><br>
  Subject: <input type="text" name="subject"><br>
  Message: <textarea rows="10" cols="40" name="message"></textarea><br>
  <input type="submit" name="submit" value="Submit Feedback">
  </form>
  <?php 
  }
else
  // the user has submitted the form
  {
  // Check if the "from" input field is filled out
  if (isset($_POST["from"]))
    {
    $from = $_POST["from"]; // sender
    $subject = $_POST["subject"];
    $message = $_POST["message"];
    // message lines should not exceed 70 characters (PHP rule), so wrap it
    $message = wordwrap($message, 70);
    // send mail
    mail("webmaster@example.com",$subject,$message,"From: $from\n");
    echo "Thank you for sending us feedback";
    }
  }
?>
Was it helpful?

Solution

This is a very basic aspect of PHP. You can find a lot of PHP tutorials online, here is what you're looking for.

http://www.w3schools.com/php/php_forms.asp

Try to use Google first before you ask a question like this.

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