Search
Here, the action attribute points to the PHP file that will process the form.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "recipient@example.com"; // replace with your email address
$subject = "New message from $name";
$headers = "From: $email";
if (mail($to, $subject, $message, $headers)) {
echo "Email sent successfully!";
} else {
echo "Failed to send email.";
}
?>
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
Combining HTML and PHP empowers you to create functional email forms. Always prioritize security, and validate form data diligently.
For further learning on PHP and HTML, consider browsing Mozilla Developer Network's guide on HTML
Please sign in to leave a comment.
Comments (0)





No comments yet. Be the first to comment!