OK, I don't see anything wrong with the code itself, although I haven't exactly learned the sending e-mails part of PHP. It's probably something else.
#1. Where are you trying to run the file from? Your computer can't run PHP unless you download the right software and stuff, which is just a pain. I strongly recommend just uploading the file to a webhost that supports a fairly recent version of PHP. I really like
ByetHost, and it's free, but it might be a little difficult to figure out how to use it.
#2. Is the file saved with a .html or .php extension? Some (maybe most) browsers aren't configured to look for PHP code in .html files. Saving it as a .php might help.
#3. Do you have the normal <html> and <body> tags around it? PHP, when being used on the web, is made to be embedded inside normal HTML code. Sometimes it may work if you don't do this, I haven't actually tried it yet, but it's recommended.
I'll tell you if I come up with more. It would help those trying to help you if you gave more specifics. What isn't working about it? Is it just doing nothing, or is it giving you an error report, or something different? Where are you hosting the file and what browser are you using? Things like that.
Another thing that would help is if you changed the if statement to this:
CODE
if(mail($to, $subject, $message, $headers));
{
echo 'MAIL SENT';
} else {
echo 'SEND FAILED';
}
Run that and tell us if it prints SEND FAILED or not. If it does, then the e-mail just isn't being sent. Maybe an invalid e-mail address? If it doesn't, then you have a coding error somewhere.