Hi all, Below is the code that I have coded after replies from all of you. But before that I want to thank all of you for your help. I have coded the email code but still it is giving me an error. Please help me. <?php //sending email script $to = "example@xxxxxxxxx"; $subject = "Email from admin"; if ($_POST['submit']) { //get data from form $name = $_POST['name']; $message = $_POST['message']; if ($name&&$message) { $namelen = 20; $messagelen = 300; if (strlen($name)<=$namelen && strlen($message)<=$messagelen) { //everything is ok ini_set("SMTP", "smtp.gmail.com"); $to = "example@xxxxxxxxx"; $subject = "Email from admin"; $header = "from: example@xxxxxxxxx"; $body = "Email from $name \n\n $message"; mail($to,$subject,$body,$header); die(); } else die ("Max length of name is $namelen, and max length for message is 300"); } else die("you must enter a name"); } ?> <html> <form action='sendemail.php' method='POST'> Name: <input type='text' name='name' maxlenght='20'><br> Message: <br><textarea name='message'></textarea><p> <input type='submit' name='submit' value='Send an email'> </form> </html> -------------------------------------------------------------------------------------- Also I have simplified the code by just using the email() function but the problem is its sending the mail in the SPAM. The code is below : <?php $to = "example@xxxxxxxxx"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "example@xxxxxxxxx"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>