PHP code for Contact form

Need a Website? Contact Us Now!

This entry is part 29 of 30 in the series phpBB Tutorials

If you have a contact form and wondering how to redirect the contact form to be redirected to your mail id, you can follow the below steps to send all your contact form details to your mail id.

Fist let us create a php folder called thankyou.php or you can do this later too, you can open dreamweaver and within the <body> tag of your code copy and paste the below php codes.

<?php
echo $name.”.  We will get back to you soon.”;
$name=$_REQUEST['name'] ;
$email=$_REQUEST['e-mail'];
$phone=$_REQUEST['phone'];
$msg=$_REQUEST['message'];

$Message = ” Form Details \n\n”;
$Message .= ” Name : $name \n”;
$Message .= ” E-mail : $email \n”;
$Message .= ” Phone : $phone \n”;
$Message .= ” Message : $msg \n”;

mail(“clement@bestwebdesignz.com”, “Website Visitors”, $Message , “From: $email\n”);
?>

You can change the mail id where it says, “clement@bestwebdesignz.com” to your mail id, now you can save the file in dreamweaver as thankyou.php

With the above step being completed, you have a file called thankyou.php.

2. While you open your contact.html page, you will see in the design part, the form which has the fields above:

PHP code for Contact form

while you click on each field inside, and check the code, you should have the same name as in the form, for example, when you click inside the Name: box of your contact form in your contact.html, the TextField must say “name” as described in your thankyou.php form, also check for all the 4 field names here.

After you do this, you must tag your form to your thankyou.php file and how to do this, you can see the below image and explaination:

PHP code for Contact form

click on the <form#form6> at the footer of  your dreamweaver and in the action part where I have circled in red you must click on the yellow folder besides that and tag your form with the thankyou.php and also select the target as _blank, now save your files and upload them to your server.

Go to the contact page in your browser ie: http://bestwebdesignz.com/contact.html and put in your name, email, phone and message there and submit the form, you should receive the details filled in the contact form to your mail id as mentioned in the php code.

That’s it, you now know how to write a PHP code for a Contact form.

PHP code for Contact form
Series Navigation«How to know if your hosting supports PHPContact PHP forms in Yahoo Smallbusiness Server»
Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • LinkedIn
  • MySpace
  • StumbleUpon
  • Technorati

Posted in phpBB Tutorials | No Comments »

Post a Comment