How to Create a mail System in PHP using HTML form

On any website have a contact page. The contact page has a form to fill and mail will deliver to the administrator. so in this article, you will learn How to Create a mail System in PHP using HTML form.

contact.php

<html>
<head>
<title>Contact US</title>
</head>
<body>
<form method="POST" action="mail.php">
<input type="text" name="name" placeholder="Enter Your Name " required />
<input type="text" name="mobile" placeholder=" Enter Your Mobile Number" required />
<input type="text" name="email" placeholder="Enter Your Email " required />
<textarea name="message"></textarea>
<input type="submit" name="submit" value="Send"/>
</form>
</body>
</html>

mail.php

<?php
$text = "<span style='color:red;'>Error! Please try again.</span>";
if(isset($_POST['submit']))
{
	$name=$_POST['name'];
	$email=$_POST['email'];
	$phn=$_POST['mobile'];
	$message=$_POST['message'];

	
	$to = "info@mail.com";
	$subject = "Contact";
	$message = " Name: " . $name ."\r\n Email: " . $email . "\r\n mobile: " . $phn . "\r\n Message:\r\n" . $message;
	 
	$from = "Contact";
	$headers = "From:" . $email. "\r\n";
	$headers .= "Content-type: text/plain; charset=UTF-8" . "\r\n"; 
	 
	if(@mail($to,$subject,$message,$headers))
	{
 echo "<script> window.location.href='contact.php;  alert('Send Successfully');</script>";
	  $text = "<span style='color:blue;'>Your Message was sent successfully !</span>";
	}
}
?>

How to Make Fees Receipt in PHP Using Mysql Database

Read on Facebook

Leave a Reply

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