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

<html>
<head>
	<title>PHP Contact Form - The Email Method - Hyvor Developer</title>
</head>
<body>

<form method="POST" action=""> 
	<div class="input-wrap">
		<span class="label">Email:</span>
		<input type="text" name="email">
	</div>
	<div class="input-wrap">
		<span class="label">Message:</span>
		<textarea name="message"></textarea>
	</div>
	<div class="input-wrap">
		<input type="submit" name="submit" value="Submit" class="submit-button">
	</div>

</form>

</body>
</html>

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

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

Tags:

Php Example