How to use PHP to collect Form data

How to use PHP to collect Form data?

Notes:
• Make sure your webserver supports PHP otherwise this solution will not work!
• This is a built-in PHP form processor. When using that option you do not need to write any code manually.

*** Recommended for beginners! ***

Step 1
Create a new page and call it feedback.
This is the page that will be displayed after the data has been submitted, so this page may contain a 'thank you for your submission' message or any other content you prefer.

Step 2
Open the page properties of the new page and set the file extension to PHP.

Step 3
Copy and paste this code at Start of your page:

<?php
$mailto = "yourname@yourdomain.com";
$subject = "Feedback form";
$message = "Values submitted from web site form:";
$header = "From: ".$_POST[’email’];
foreach ($_POST as $key => $value)
{
   if (!is_array($value))
   {
      $message .= "\n".$key." : ".$value;
   }
   else
   {
      foreach ($_POST[$key] as $itemvalue)
      {
         $message .= "\n".$key." : ".$itemvalue;
      }
   }
}
mail($mailto, $subject, stripslashes($message), $header);
?>

Note:
Your form should contain a field called email, this field will be used as sender of the mail message!

Step 4
Replace yourname@yourdomain.com with your own email address.

Step 5
Go back to the page with your form and set the action property of the form to feedback.php.
Verify that the method is set to POST.
Also there is no need for encodingtype field so that it's empty.

Step 6
The First Page is your input form and second page is feedback.php which collect user form data and submit to given email. Now you can publish the 2 pages and test your form.

Note:
You can not test a PHP form on your local computer, the script should be executed on a web server with PHP support!

MrHitech Author

The Guest's post, tutorial and FAQ (s) will be updated through this account. For any query/suggestion please feel free to contact us. We're on: @Facebook @twitter @Google+ @Linkedin @Youtube