I had the same problem and found after running a port testing PHP script that I needed to configure linux (Centos in my case) to allow httpd to access TCP ports using the following command on the command line:
setsebool httpd_can_network_connect=1
or permanently by
setsebool -P httpd_can_network_connect=1
NB: using the -P option took over 2 minutes on my machine so be patient
Hey presto! my mail command worked.
My situation was that I was able to send mail to my ISP's SMTP Server ie mail.optusnet.com.au Port 25 from the command line but not using PHP scripts ran in my browser.
Also, ensure that your firewall is not interfering with PHP by running a Telnet session to you SMTP host.
eg $telnet mail.optusnet.com.au 25
In your case I suspect not as you are able to send emails from the Command Line.
I hope that helps