send contact form to mail in html format using php mail function code example
Example 1: how to connect contact form to email in php
<?php
if(!empty($_POST["send"])) {
$name = $_POST["userName"];
$email = $_POST["userEmail"];
$subject = $_POST["subject"];
$content = $_POST["content"];
$toEmail = "admin@phppot_samples.com";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if(mail($toEmail, $subject, $content, $mailHeaders)) {
$message = "Your contact information is received successfully.";
$type = "success";
}
}
require_once "contact-view.php";
?>
Example 2: how to connect contact form to email in php
if (empty($emailError) && empty($messageError)) {
// all the code should go here
}
Example 3: how to connect contact form to email in php
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// your other code here
}