Here’s how to simply submit a contact form and email with PHP:
NOTE: this is a simple quick option, for more complicated and robust forms I recommend using a free service like http://icebrrg.com which can create much more professional looking and feature rich forms.
Step 1: Create your form.
Create a standard html form, it needs to have at least a “name” and “email” field. You can add as many extra fields to this as you like.
<form action="formsubmit.php" method="post">
Your Name: <input name="name" type="text" /> <br />
Your Email: <input name="email" type="text" /> <br />
Your Message: <textarea name="your_message" cols="30" rows="10"></textarea> <br />
<input name="submit" value="Submit Message" type="submit" />
Step 2: Create the PHP.
Download the sample “formsubmit.php” file by clicking here: download formsubmit.php
This PHP script uses the standard php mail() command and will work on majority of php hosting accounts. This file needs to be uploaded to your website along with your form above.
Step 3: Customise.
At the top of the formsubmit.php file you need to set the to address and the email subject. You can also set an option CC and BCC address.
This script redirects to a thankyou.html file once successfully submitted, you will need to make this as well with a thank you message in it. If any required fields are missing an error message will display, you can customise this error message about half way through the formsubmit.php file.
You can also have a <input type=”hidden” name=”subject” value=”Custom Subject”> if you wish to use the same formsubmit.php file multiple files on your site, but you need a different subject for each different form.
Step 4: Result.
If all goes to plan, the result should come through in your email something like this:
Sample Website Contact
Name: Testing Name
Your Message: testing message