Is this script working anywhe else?
As Corion said above, check your maillog. The errors sounds like sendmail may have relaying locked down, at least that's what has happened to me in the past, Maybe the apache user is prevented from mailing as a security measure. Perhaps you need to use something that will allow you to pass user and password information to let you mail out. What OS and server config?