If you want to make contact form in php pages this tutorial help you to make email form.In this user contact detail come on your email from the form submission. This is so easy to make and use if you have knowledge of Php you can edit and make your own conditions, Recently i make this contactt Us page code .your contact form code look like this and you can make this for your own design by using CSS .
How to make contact form ?
Make a form in html using this code:
<form name=”ajax-form” id=”ajax-form” action=”mail-it.php” method=”post”>
<span class=”error” id=”err-name”>please enter name</span>
<input name=”name” id=”name” type=”text” placeholder=”Full Name” />
<span class=”error” id=”err-email”>please enter e-mail</span>
<span class=”error” id=”err-emailvld”>e-mail is not a valid format</span>
</label>
<input name=”email” id=”email” type=”text” placeholder=”E-mail” />
<input name=”contact” type=”text” placeholder=”Contact No.” />
<textarea name=”comment” id=”message” placeholder=”Write your Comment”></textarea>
<input class=”send_message” id=”send” type=”submit” />
</form>
How to send info from contact form to mail?
<?php
/* Set recipient e-mail */
$myemail = “[email protected]”;
/* Check all form inputs using check_input function */
$name = check_input($_POST[‘name’], “Enter your name”);
$contact = check_input($_POST[‘contact’], “Enter your contact no”);
$email = check_input($_POST[’email’]);
$comment = check_input($_POST[‘comment’], “Write your comment”);
/* If e-mail is not valid show error message /
if (!preg_match(“/([\w-]+\@[\w-]+.[\w-]+)/”, $email))
{
show_error(“Please enter a valid email”);
}
/ Let’s prepare the comment for the e-mail */
$comment = ”
Name: $name
E-mail: $email
Contact: $contact
Comment:$comment
“;
/* Send the comment using mail() function */
mail($myemail, $contact, $comment);
/* Redirect visitor to the thank you page /
header(‘Location: http://liveurlifehere.com/thanks’);
exit();
}
/ Functions we used */
function check_input($data, $problem=”)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
Leave a Reply