Your php.ini isn´t configured to use a mail server ... or, like in my case,you are testing it through a proxy server...
Anyway... look at your php.ini at:
[mail function]
; For Win32 only.
SMTP = smtp.dude.com
; For Win32 only.
sendmail_from = dude@dude.com
; For Unix only. You may supply arguments as well (default: 'sendmail -t -i').
;sendmail_path =
if this part of the ini isn´t properly writen, then PHP can´t conect to the mail server, that´s "Failed to Connect" message...
hope it helps...
ps.. Are you testing it at home or directly in the server??