too long

This question already has an answer here:

<?php
$to = "karthik.hansi@infysky.com";
$subject = "First php test script";
$message = "Hi This message is for leave application ";
$headers = "From:karthik.hansi@infysky.com";
if(mail($to, $subject, $message, $headers))
{
echo "failed";

}else{
echo "sent";
}

?> 

This is My code I have tried this sending mail from PHP not able to send mail anything I have to configure in xampp.

</div>

You can use libmail: http://lwest.free.fr/doc/php/lib/index.php3?page=mail&lang=en

include "libmail.php";
$m = new Mail(); // create the mail
$m->From( "leo@isp.com" );
$m->To( "destination@somewhere.fr" );
$m->Subject( "the subject of the mail" );
$m->Body( "Hello
This is a test of the Mail component" );
$m->Cc( "someone@somewhere.fr");
$m->Priority(4);
//  attach a file of type image/gif to be displayed in the message if possible
$m->Attach( "/home/leo/toto.gif", "image/gif", "inline" );
$m->Send(); // send the mail
echo "Mail was sent:"
echo $m->Get(); // show the mail source
   $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPDebug = 1;
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = 'ssl';
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 465;
    $mail->IsHTML(true);
    $mail->Username = "yourname@gmail.com";
    $mail->Password = "your_pass";
    $mail->SetFrom("your_email");
    $mail->Subject = "your_title";
    $mail->Body = "your_body";
    $mail->AddAddress("receiver_email");
    if (!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message has been sent";
    }

You have to include phpmailer library. You can download it from here phpmailer

After that you go to your gmail account that you want to use as sender and you need to set 2-step verification ---> off and Allow less secure apps ---> ON.

This guide may help you set up gmail for send emails with php

I am using this script and works fine just make sure to set up all the changes. Maybe you have to add some changes in your xampp ( i did not but i don't know your php.ini file so keep that in mind).