contact form php send to email 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

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	// your other code here
}

Tags:

Php Example