This should be a comment, but its a bit long.
You've not provided nearly enough information here.
It has been suggested that we need to see the code - if your description is accurate then we don't, however given the quality of information supplied the predicate is very dubious. What happens when you run something like:
<?php
print "started<br />
";
while (ob_get_level()) ob_flush();
flush();
$result=mail('youruser@localhost', 'test', 'test');
print "result=" . var_export($result, true);
exit;
What do the access and error logs show for the script?
What does your MTA logs show?
What is your MTA?
What OS is this running on?
but runs fine on SSH
Does your CLI SAPI use the same php.ini files as the web server?
If not what are the respective configurations?
Are you running the CLI as the webserver uid?
(hint - that's 8 questions you need to answer before anyone can make an informed guess as to what's happenning here)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…