First a few infos:
mail()
in this case. For all my other
Most likely you use 2 different php.ini versions. one for cli and one for cgi. Debian have this setup i believe.
Make sure that your cli and cgi versions have the same email configuration and it will work.
The mail configuration key is: [mail function]
Another possibility is that your web user does't have access to execute sendmail.
Also check spool permissions (updated)