Drompo
22-02-2007, 12:15 PM
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.
<?php
$ipi = getenv("REMOTE_ADDR");
?>That will get the users IP address
The first line of code is the beginning of the form and also tells the data where to output.
<form method="post" action="sendmail.php">
You can change the "sendmail.php" to whatever you like as long as it complies with the output file.
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;
Name: <input type="text" name="name" size="30" />
Now to show the Email Address Box we would put;
Email Address: <input type="text" name="email" size="30" /><br />
Now the Drop down menu is more complicated.
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>
The Name after "Option value="NAME" that is the tag that will be the subject of the email you recieve.
Finally The Main message.
<textarea name="main" rows="4" cols="30"></textarea>
You can make the area bigger/smaller by changing the numbers above.
and now the user will submit the form
<input type="submit" value="Send" />
and then end the form
</form>
In the End Looking like this
<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
<?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);
?>
Do Not edit that code unless you know what your doing.
Where it says
mail("YourEmail", $subject, $message, $from);
Edit Youremail to The email address you want it to send it to.
And there you have your contact form.
Types Of Inputs:
Text Field
Text Field:
<input type="text" name="fieldname">
Radio Buttons
Options:
<input type="radio" name="fieldname" value="option 1"> Option 1
<br>
<input type="radio" name="fieldname"" value="option 2"> Option 2
Checkboxes
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
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>
TextAreas
<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 :).
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.
<?php
$ipi = getenv("REMOTE_ADDR");
?>That will get the users IP address
The first line of code is the beginning of the form and also tells the data where to output.
<form method="post" action="sendmail.php">
You can change the "sendmail.php" to whatever you like as long as it complies with the output file.
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;
Name: <input type="text" name="name" size="30" />
Now to show the Email Address Box we would put;
Email Address: <input type="text" name="email" size="30" /><br />
Now the Drop down menu is more complicated.
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>
The Name after "Option value="NAME" that is the tag that will be the subject of the email you recieve.
Finally The Main message.
<textarea name="main" rows="4" cols="30"></textarea>
You can make the area bigger/smaller by changing the numbers above.
and now the user will submit the form
<input type="submit" value="Send" />
and then end the form
</form>
In the End Looking like this
<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
<?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);
?>
Do Not edit that code unless you know what your doing.
Where it says
mail("YourEmail", $subject, $message, $from);
Edit Youremail to The email address you want it to send it to.
And there you have your contact form.
Types Of Inputs:
Text Field
Text Field:
<input type="text" name="fieldname">
Radio Buttons
Options:
<input type="radio" name="fieldname" value="option 1"> Option 1
<br>
<input type="radio" name="fieldname"" value="option 2"> Option 2
Checkboxes
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
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>
TextAreas
<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 :).