Hello, I am going to take you through the nessecery steps to making a contact form.
First off i will explain what i am going to do.
I am going to make two files:
- One to show the contact form (contact.php)
and one to send the contact form. (sendmail.php)
First make a blank page in Notepad or Dreamweaver.
Before the actull code add this.
That will get the users IP addressCode:<?php $ipi = getenv("REMOTE_ADDR"); ?>
The first line of code is the beginning of the form and also tells the data where to output.
You can change the "sendmail.php" to whatever you like as long as it complies with the output file.Code:<form method="post" action="sendmail.php">
Now you need to work out what fields you want. Inn this instance we are going to use:
-Name (Text Box)
-Email Address (Text Box)
-Contact Reason (Drop Down Box)
-Message (Text Area)
I will list the input codes for various inputs later on.
Now to show the Name Box we would put;
Now to show the Email Address Box we would put;Code:Name: <input type="text" name="name" size="30" />
Now the Drop down menu is more complicated.Code:Email Address: <input type="text" name="email" size="30" /><br />
The Name after "Option value="NAME" that is the tag that will be the subject of the email you recieve.Code:Contact Reason:<br /> <select name="reason" size="1"> <option value="Website Problem">Website Problem</option> <option value="Billing Problem">Billing Problem</option> <option value="Technical Support">Technical Support </option> <option value="Report A Staff Member ">Report A Staff Member</option> <option value="Other">Other (Please Specify in message)</option> </select>
Finally The Main message.
You can make the area bigger/smaller by changing the numbers above.Code:<textarea name="main" rows="4" cols="30"></textarea>
and now the user will submit the form
and then end the formCode:<input type="submit" value="Send" />
In the End Looking like thisCode:</form>
Code:<form method="post" action="sendmail.php"> Email Address: <input type="text" name="email" size="30" /><br /> Contact Reason:<br /> <select name="reason" size="1"> <option value="Website Problem">Website Problem</option> <option value="Billing Problem">Billing Problem</option> <option value="Technical Support">Technical Support </option> <option value="Report A Staff Member ">Report A Staff Member</option> <option value="Other">Other (Please Specify in message)</option> </select> <textarea name="main" rows="4" cols="30"></textarea><br /> <input type="submit" value="Send" /> </form>Now Call this sendmail.php
Do Not edit that code unless you know what your doing.Code:<?php if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { die ("Invalid Email Address"); $badinput = "<h2>Feedback was NOT submitted</h2>\n"; echo $badinput; } if(empty($visitor) || empty($visitormail) || empty($notes )) { die ("You didn't fill in all the fields"); } $subject = $reason; $message = "Reason: $reason \n Message: $main \n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n "; $from = "From: $email\r\n"; mail("YourEmail", $subject, $message, $from); ?>
Where it saysEdit Youremail to The email address you want it to send it to.Code:mail("YourEmail", $subject, $message, $from);
And there you have your contact form.
Types Of Inputs:
Text Field
Code:Text Field: <input type="text" name="fieldname">
Radio Buttons
Code:Options: <input type="radio" name="fieldname" value="option 1"> Option 1 <br> <input type="radio" name="fieldname"" value="option 2"> Option 2
Checkboxes
Code:Options: Option 1 <input type="checkbox" name="fieldname" value="option 1" /> <br /> Option 2 <input type="checkbox" name="fieldname" value="option 2" />
Drop Down Box
TextAreasCode:Options: <select name="options"> <option value="Option 1">Option 1</option> <option value="Option 2">Option 2</option> <option value="Option 3">Option 3</option> <option value="Option 4">Option 4</option> </select>
Code:<textarea name="fieldname" rows="4" cols="30"></textarea>
Edited by Lµke (Forum Moderator): Thread Moved From Website Designing. Please post in the correct section next time, Thanks.





.
Reply With Quote






