Simple Contact Form script in PHP

This is a Simple Contact Form script in PHP. First we are creating form in html. After that sending the mail to specific mail address. We are checking all the post values are set or not, next we are checking for the values are empty or not. After that if values are not empty then we are sending the mail. This is simple contact form without any styles. You can add styles as you want.

Code for Simple Contact Form script in PHP

Simple Contact Form script in PHP

<?php
	if(isset($_POST['name']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['message'])){
		$name = $_POST['name'];
		$email = $_POST['email'];
		$subject = $_POST['subject'];
		$message = $name . "/n/n" . $_POST['message'];
		if(!empty($name) || !empty($email) || !empty($subject) || !empty($message)){
			$to = "codingcyber@gmail.com";
			$headers = "From :" . $email;
			if(mail($to, $subject, $body, $headers)){
				echo "Message Sent Success.";
			}else{
				echo "Message Failed";
			}
		}else{
			echo "All fields requierd";
		}
	}
 ?>
 <html>
	 <head>
		<title>Simple Contact Form</title>
	 </head>
	 <body>
		<form action="" method="post">
			<label>Name: </label><br />
			<input type="text" name="name"><br /><br />
			<label>Email: </label><br />
			<input type="text" name="email"><br /><br />
			<label>Subject: </label><br />
			<input type="text" name="subject"><br /><br />
			<label>Message: </label><br />
			<textarea name="message" cols="30" rows="5" ></textarea><br /><br />
			<input type="submit" value="Send" />
		</form>
	 </body>
 </html>

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe