Sending email via PHP fails

I have an Apache 2.2.4 server with PHP 5.2 installed on it. PHP works since phpinfo() function displays the information about PHP, but when i ran this script:


<?php
$to = "myemail@gmail.com";
$subject = "Hi!";
$body = "Hi,

How are you?";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
 } else {
  echo("<p>Message delivery failed...</p>");
 }
?>

it always returns “Message delivery failed…”. The email is real and exists.
Now i dont know if its a server problem or a script problem. Im not really very good at either of them so i would like to ask for your expertise on this subject:)