Hi,
Please go to Untitled Document and click the contact tab.
There is a form over there, how do i make it like a working contact form?
Please can someone help me out.
Thanks!
Printable View
Hi,
Please go to Untitled Document and click the contact tab.
There is a form over there, how do i make it like a working contact form?
Please can someone help me out.
Thanks!
It's actually very simple, I just learned how :)
Let's take a look at your HTML form:
The important parts are the action="send.php" and the name="X" for the fields.HTML Code:<form action="send.php" method="post">
<img src="http://www.netbuilders.org/images/leave-a.gif" alt="Leave a message">
<ul>
<li><input class="text-name" name="contact_name" type="text"></li>
<li><input class="text-email" name="contact_email" type="text"></li>
<li><textarea class="message" rows="2" cols="25" name="the_message"></textarea></li>
<li><input src="http://www.netbuilders.org/images/send.gif" class="submit" alt="submit" type="image"></li></ul></form>
Now, let's look at send.php that I just whipped up:
And we'll break it down.PHP Code:<?php
// Your Email Here
$to = "youremail@yourdomain.com";
// The 'From' Email
$from = "from@yourdomain.com";
// Subject of Email
$subject = "New Contact Form Response";
$name = $_POST['contact_name'];
$email = $_POST['contact_email'];
$message = $_POST['the_message'];
$name_new = filter_var($name, FILTER_SANITIZE_STRING);
$email_new = filter_var($email, FILTER_SANITIZE_STRING);
$message_new = filter_var($message, FILTER_SANITIZE_STRING);
$headers = "From: $from";
$body = "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n";
mail($to, $subject, $body,$headers);
?>
Normal HTML here
This is simply setting variables so you don't have to edit the mess.PHP Code:<?php
// Your Email Here
$to = "youremail@yourdomain.com";
// The 'From' Email
$from = "from@yourdomain.com";
// Subject of Email
$subject = "New Contact Form Response";
These are more variables, and they call upon the form. Where it says $_POST['contact_name'] you would put the name of your field, in this case being contact_name. You would do the same with the rest.PHP Code:$name = $_POST['contact_name'];
$email = $_POST['contact_email'];
$message = $_POST['the_message'];
This replaces the old variables, sanitizes them (removes any HTML markup), and puts them into new variables.PHP Code:$name_new = filter_var($name, FILTER_SANITIZE_STRING);
$email_new = filter_var($email, FILTER_SANITIZE_STRING);
$message_new = filter_var($message, FILTER_SANITIZE_STRING);
This is the actual email. $headers is going to be the From section, leave it as it is. The $body is what appears in the email. \n is a break. The variables are in it as well (notice we are using the sanitized ones). This is what the email would look like:PHP Code:$headers = "From: $from";
$body = "##################################################\nTHIS IS AN AUTOMATED EMAIL - DO NOT RESPOND\n##################################################\n\nSomebody just sent you a message using your contact form.\n\nName: $name_new\nEmail: $email_new\nMessage:\n$message_new\n\n";
Quote:
##################################################
THIS IS AN AUTOMATED EMAIL - DO NOT RESPOND
##################################################
Somebody just sent you a message using your contact form.
Name: $name_new
Email: $email_new
Message:
$message_new
This is the final function that actually sends out the email. Now, you can put normal HTML after this, and that would be your 'Email sent!' page.PHP Code:mail($to, $subject, $body,$headers);
?>
Normal HTML here
This is a simple form, without validation or anti-spam. Just look up a Google search for that.