php mail() sends from command line but fails when accesses from web

I can send an email from the command line using this

<?PHP
$sender = 'someone@somedomain.tld';
$recipient = 'you@yourdomain.tld';

$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;

if (mail($recipient, $subject, $message, $headers))
{
    echo "Message accepted";
}
else
{
    echo "Error: Message not accepted";
}
?>

but in the browser I get "Not Accepted" and I am not sure why.

Status: 
Closed (fixed)

Comments

Nevermind, i fixed this

I had to use "/usr/sbin/sendmail -t -i" instead of "/usr/bin/mail" for it to work properly.

I am marking this fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.