The problem is that you are not running an incoming mail server (listening on SMTP port 25) on your machine (where the PHP script is executed), which it happens to connect to by default.
If you can install a SMTP server locally easily, e.g. in Linux by installing a "sendmail" package, you can solve it like that.
If you don't want to run such a server, you must at least modify your php.ini
to set a SMTP server of your internet or mail provider instead. Search for smtp
in the .ini file and fill the variables accordingly.