First of all if you are using the script on production server then ask your admin for the mail function is active or not . Some time on production server it's blocked by Site admin.
Second if you are using this script on localhost server means on your desktop then first you have to use the mail server start.
for example i am considering that you are using XAMMPP on windows then Your have to start the Mercury Mail Server From the XAMPP control panel.
Mercury by default comes with postmaster and newuser two users.
Then You have to download Mozilla Thunderbird mail client and configure the
newuser and postmaster user in mail client by following the Create New account > email using the newuser@localhost and manually configure the pop and smtp server and port . usually default ports.
you can use the sendmail_from ="newuser@localhost"
then check Mercury Mail server is running then test your script.
it will send the mail and you then check it in the Mozilla Thunderbird mail client.
Third : for setting the From:
you have to use the header
like below
$headers = "From: newuser < [email protected] >\n";
<?php
$send_to = 'postmaster@localhost';
$mail_subject = 'Subject of Your mail';
$message_body = 'Body of your email like message form php script.';
$headers = 'From: newuser@localhost' . "\r\n";
mail($send_to, $mail_subject, $message_body, $headers);
?>
I hope this will solve the problem .
NOTE if you want to send email form localhost to gamil or any other mail site then you have to use the sendmail application or more tutorial Search the google Term like 'Send email via Gmail in PHP '