Contact form



Simple Contact Form











contact.html

In this contact form shows required text fields for sending the message

After submit the form it will directly link to the mail.php

<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<div id="container">
<form name="form" action="mail.php" method="POST">
<lable for="name">Name</lable>
<input type="text" name="name" value=" ">
<lable for="email">Email</lable>
<input type="text" name="email" value=" ">
<lable for="phone">Phone No</lable>
<input type="text" name="phone" value=" ">
<lable for="message">Message</lable>
<input type="text" name="message" value=" ">
<input type="submit" name="submit" value="Login">
</form>
</div>
</html>

connect.php

This is mysql connection page here we have to give hostname, username and password and database name

<?php
mysql_connect("localhost","root","123")or die("couldnot connect:". mysql_erro());
mysql_select_db("contact") or die("couldnot connect:". mysql_erro());
?>

mail.php

Finally this is the contact page after submit the form ie contact.html the input values are send to specific Email

$userName=$_POST['name'];
$userEmail=$_POST['email'];
$userPhone=$_POST['phone'];
$userMsg=$_POST['message'];
//you can change your subject line
$subject = "Message from ".$userName;
//Replace your email id
$email_id='koppalavenky@gmail.com';
$message = '<html><head><title>'.$subject.'</title></head><body><table>
<tr><td>Email id : </td></tr> '.$userEmail.'</tr></td>
<tr><td>Phone No : </td></tr> '.$userPhone.'</tr></td>
<tr><td> Name : </td></tr> '.$userName.'</tr></td>
<tr><td> Says : </td></tr> '.$userMsg.'</tr></td>
</body><table>
$to=$email_id;
$headers = "From: " . strip_tags($userEmail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($userEmail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if(!mail($to, $subject, $message, $headers)){
$mail_status='no';
echo "sorry try again ";
exit();
}else{
$mail_status='yes';
echo "Thank you for contacting us;
exit();

} ?>
?>

No comments: