Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ThomasNormansProject/contact-form-handler.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (37 sloc)
1.18 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session_start(); | |
<?php | |
$errors = ''; | |
$myemail = 'thomas-99@hotmail.co.uk';//<-----Put Your email address here. | |
if(empty($_POST['name']) || | |
empty($_POST['email']) || | |
empty($_POST['timeslot']) || | |
empty($_POST['message'])) | |
{ | |
$errors .= "\n Error: all fields are required"; | |
} | |
$name = $_POST['name']; | |
$email_address = $_POST['email']; | |
$message = $_POST['message']; | |
$timeslot = $_POST['timeslot']; | |
if (!preg_match( | |
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", | |
$email_address)) | |
{ | |
$errors .= "\n Error: Invalid email address"; | |
} | |
if( empty($errors)) | |
{ | |
$to = $myemail; | |
$email_subject = "Contact form submission: $name"; | |
$email_body = "You have received a new message. ". | |
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $timeslot \n $message"; | |
$headers = "From: $myemail\n"; | |
$headers .= "Reply-To: $email_address"; | |
mail($to,$email_subject,$email_body,$headers); | |
//redirect to the 'thank you' page | |
header('Location: contact-form-thank-you.html'); | |
} | |
?> | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> |