send contact us page directly through email with php code example

Example 1: how to connect contact form to email in php

<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
	if (empty($_POST['email'])) {
		$emailError = 'Email is empty';
	} else {
		$email = $_POST['email'];
		// validating the email
		if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
			$emailError = 'Invalid email';
		}
	}

	if (empty($_POST['message'])) {
		$messageError = 'Message is empty';
	} else {
		$message = $_POST['message'];
	}
}

Example 2: how to connect contact form to email in php

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

Tags:

Php Example