How to send email from a php application using localhost

You can use the following code to send email from a php application using localhost (without SMTP authentication).
 
<html>
<head>
<title>Test email via php</title>
</head>
<body>
<?php
 $to = "user@YourHostedDomainName.com";
 $subject = "Testing php mail";
 $message = "This is a test,\n\ndo you see it?";
 $headers = "From: postmaster@YourHostedDomainName.com";
 if (mail($to, $subject, $message, $headers)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }
  ?>
</body>
</html>