<?php
$submit = !empty($_REQUEST['submit']);
?>
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="UTF-8" />
<?php if( $submit ){ ?><meta HTTP-EQUIV="Refresh" CONTENT="3; URL=" /><?php } ?>
<title>Email test</title>
<style type="text/css">
label{display: block;}
input,textarea{margin-bottom:15px;}
</style>
</head>
<body>
<?php
// Display the contact form:
if( !$submit )
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<label>Your name</label>
<input name="name" type="text" value="" size="30"/>
<br/>
<label>Your email</label>
<input name="email" type="email" value="" size="30"/>
<br/>
<label>Your message</label>
<textarea name="message" rows="7" cols="30"></textarea>
<br/>
<input name="submit" type="submit" value="Send email"/>
</form>
<?php
}
// Send the submitted data:
else
{
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
if( empty($name) || empty($email) || empty($message) )
{
?><p>All fields are required.<br/>You will be redirected in 3 seconds.</p><?php
}
else
{
$from = "From: $name<$email>\r\nReturn-path: $email";
$subject = "Message sent using your contact form";
mail( $email/*TO*/, $subject, $message, $from ) ;
?><p>Email sent!<br/>You will be redirected in 3 seconds.</p><?php
}
}
?>
</body>
</html>