Here is an simple example
Create a file contact_us.php
and write bellow code there.
<!DOCTYPE html>
<html>
<head>
<title>Contact Us Form</title>
</head>
<body>
<h1>Contact Us</h1>
<?php
if (isset($_POST[‘submit’])) {
$name = $_POST[‘name’];
$email = $_POST[’email’];
$message = $_POST[‘message’];
$to = ‘your-email@example.com’;
$subject = ‘Contact Us Form Submission’;
$headers = “From: $email\r\nReply-To: $email\r\n”;
$mailBody = “Name: $name\nEmail: $email\n\n$message”;
if (mail($to, $subject, $mailBody, $headers)) {
echo ‘<p>Your message has been sent!</p>’;
} else {
echo ‘<p>Something went wrong, please try again!</p>’;
}
}
?>
<form method=”post”>
<label for=”name”>Name:</label><br>
<input type=”text” id=”name” name=”name” required><br>
<label for=”email”>Email:</label><br>
<input type=”email” id=”email” name=”email” required><br>
<label for=”message”>Message:</label><br>
<textarea id=”message” name=”message” required></textarea><br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
</body>
</html>
