<?php
$to      
=   '';
$from    =   '';
$subject =   '';
$headers =   '';

if((!empty(
$_POST['to'])) && (!empty($_POST['from'])) && (!empty($_POST['subject'])) && (!empty($_POST['message']))) {
  
$to      $_POST['to'];
  
$from    $_POST['from'];
  
$subject $_POST['subject'];
  
$message $_POST['message'];
  
$headers =   "From: $from"\r\n" 'X-Mailer: PHP/' phpversion();

  if(
mail($to$subject$message$headers)) {
    echo 
"
    <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
    <html>
    <head>
    <title>Example E-Mail Form</title>
    </head>
    <body>
    Message has been sent!
    </body>
    </html>
    "
;
  } 
  else {
    echo 
"
    <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
    <html>
    <head>
    <title>Example E-Mail Form</title>
    </head>
    <body>
    Message delivery failed!
    </body>
    </html>
    "
;
  } 
}
else {
  echo 
"
  <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">
  <html>
  <head>
  <title>Example E-Mail Form</title>
  </head>
  <body>
  <p>Fill in the fields below and hit the \"Submit E-Mail\" button to mail your message.</p>

  <form method=\"post\" action=\"email.php\">

  <p>To:<br><input type=\"text\" name=\"to\" size=\"50\" maxlength=\"256\"></p>

  <p>From:<br><input type=\"text\" name=\"from\" size=\"50\" maxlength=\"256\"></p>

  <p>Subject:<br><input type=\"text\" name=\"subject\" size=\"50\" maxlength=\"256\"></p>

  <p>Message:<br><textarea name=\"message\" rows=\"15\" cols=\"50\"></textarea></p>

  <p><input type=\"submit\" value=\"Submit E-Mail\"></p>
  </form>
  </body>
  </html>
  "
;
}

?>