There might be more things wrong but let's start with the obvious:
$to = 'example@gmail.com';
This should contain your email address if you want to receive something.
Can you fix that and test again? If it doesn't work yet we can go a step further.
EDIT AFTER YOUR ANSWER: I have done that already i am messaging from my gmail account to one of my friend gmail account. Is I am making any mistake?
With the code you made php will try to send the email with the mail server which is in your configurations: to send an email with GMAIL you need to fix your code. This is an example of how you can use phpmailer to send it:
//include the file
require_once('class.phpmailer.php');
$phpmailer = new PHPMailer();
$phpmailer->IsSMTP(); // telling the class to use SMTP
$phpmailer->Host = "ssl://smtp.gmail.com"; // SMTP server
$phpmailer->SMTPAuth = true; // enable SMTP authentication
$phpmailer->Port = 465; // set the SMTP port for the GMAIL server; 465 for ssl and 587 for tls
$phpmailer->Username = "yourname@yourdomain"; // Gmail account username
$phpmailer->Password = "yourpassword"; // Gmail account password
$phpmailer->SetFrom('name@yourdomain.com', 'First Last'); //set from name
$phpmailer->Subject = "Subject";
$phpmailer->MsgHTML($body);
$phpmailer->AddAddress($to, "To Name");
if(!$phpmailer->Send()) {
echo "Mailer Error: " . $phpmailer->ErrorInfo;
} else {
echo "Message sent!";
}
from: https://stackoverflow.com/a/16022357/2042240
I really suggest you to use phpmailer (http://phpmailer.worxware.com/) since it is very powerful and easy to use. When you have downloaded the library just import it as in the example i showed you and you're ready to go.
EDIT 2: if you still prefer using the mail() function here you can see how you can enable GMAIL with it: https://www.digitalocean.com/community/tutorials/how-to-use-gmail-or-yahoo-with-php-mail-function