<?php
$to = "you@yoursite.com";
$subject = "Contact Us";
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "We encountered an error sending your mail"; }
?> Save the above code as contact.php
What this code does is:
- Define who you want the mail sent to. We have used you@yoursite.com but you should replace this with your email address.
- Define the default subject for your mail.
- Collect the message and email fields from the form and assign them to variables
- Create a 'from' email header
- Send the email
While PHP contact scripts can vary in complexity and features, they all use this mail function as their base. We suggest you follow up by reading our tutorial on creating a more detailed contact form



