Mail html form
A classic!
To send an HTML form via email, you'll need to use a combination of HTML, CSS, and server-side programming (e.g., PHP, Python, or JavaScript). Here's a basic example of how to create a simple HTML form that sends an email using PHP:
HTML Form
<form action="send_email.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea><br><br>
<input type="submit" value="Send">
</form>
PHP Script (send_email.php)
<?php
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form data
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// Set the email headers
$to = "[email protected]";
$subject = "Contact Form Submission";
$headers = "From: $email\r\nReply-To: $email\r\nContent-Type: text/plain; charset=UTF-8";
// Send the email
mail($to, $subject, $message, $headers);
// Display a success message
echo "Thank you for contacting us!";
} else {
// Display the form if it hasn't been submitted
?>
<form action="send_email.php" method="post">
<!-- Form fields go here -->
</form>
<?php
}
?>
How it works
- The HTML form is created with input fields for name, email, and message.
- The form is submitted to the PHP script (
send_email.php
) using theaction
attribute. - The PHP script checks if the form has been submitted using the
$_SERVER["REQUEST_METHOD"]
variable. - If the form has been submitted, the script retrieves the form data using the
$_POST
superglobal. - The script sets the email headers using the
mail()
function. - The script sends the email using the
mail()
function. - If the email is sent successfully, the script displays a success message.
Note: This is a basic example, and you should consider implementing additional security measures, such as validating user input and preventing spam submissions.
Also, make sure to replace [email protected]
with the actual email address you want to receive the form submissions.