Simple HTML Contact Form to send Email in PHP

Fist of All we will create a HTML Form

<form role="form" action="submit.php" method="post">
<input name="name" required="required" type="text" placeholder="Enter Your Name" />
<input name="email" required="required" type="email" placeholder="Email ID"/>
<input name="mobile" required="required" type="text" placeholder="Enter Mobile No"/>
<textarea name="message" placeholder="Enter Any Message"></textarea>
<input name="submit" type="submit" value="Send a Mail" /></form>

Preview will be look like this
html form for send a mail

Now we will create a file submit.php for send a mail in PHP

		$name = $_POST['name']; // Get Name value from HTML Form
		$email_id = $_POST['email']; // Get Email Value
		$mobile_no = $_POST['mobile']; // Get Mobile No
		$msg = $_POST['message']; // Get Message Value
		$to = ""; // You can change here your Email
		$subject = "'$name' has been sent a mail"; // This is your subject
		// HTML Message Starts here
		$message ="
				<table style='width:600px;'>
							<td style='width:150px'><strong>Name: </strong></td>
							<td style='width:400px'>$name</td>
							<td style='width:150px'><strong>Email ID: </strong></td>
							<td style='width:400px'>$email_id</td>
							<td style='width:150px'><strong>Mobile No: </strong></td>
							<td style='width:400px'>$mobile_no</td>
							<td style='width:150px'><strong>Message: </strong></td>
							<td style='width:400px'>$msg</td>
		// HTML Message Ends here
		// Always set content-type when sending HTML email
		$headers = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

		// More headers
		$headers .= 'From: Admin <>' . "\r\n"; // Give an email id on which you want get a reply. User will get a mail from this email id
		$headers .= 'Cc:' . "\r\n"; // If you want add cc
		$headers .= 'Bcc:' . "\r\n"; // If you want add Bcc
			// Message if mail has been sent
			echo "<script>
					alert('Mail has been sent Successfully.');

			// Message if mail has been not sent
			echo "<script>
					alert('EMAIL FAILED');

Now you are ready to send a mail through HTML form in PHP


You may also like

4 comments on “Simple HTML Contact Form to send Email in PHP

Leave a Reply

Your email address will not be published. Required fields are marked *