Given the semi complex nature of your setup and the fact you've not told us if you're using sendmail, fakesendmail, SMTP etc, there isn't going to be a great deal that we can do to advise you here.
As for the coding issue, while the code may work perfectly well on one machine, it's quite possible for it not to run on another. Just silly things like one machine having a slightly different PHP version can cause problems. I worked on a project a while back that I developed using PHP 5.3 and when I uiploaded it to the server (running 5.0) all hell broke loose. Nothing really worked, the use of the date() function seemed to be knackered and I spent many hours debugging it to keep my rather worried client happy (and traced it down to something really silly to do with a 5.0 and 5.3 difference using the date() function iirc).
Now, your log shows one email accepted for delivery and another saying the service is unavailable. That could indicate thatr you're having spam problems outside of your network - EG your IP is blocked, maybe even port 25 or worse, your IP is on a spam blacklist. There are many reasons. I think you're going to have to run a local mail server and see if you can at least send mail @localhost just to be sure that it is actually sending and then try sending to a mailserver on another machine (or even your VM host) before trying to send mail out of the network again. It's a gradual process of trial and error to determine where the fault in the process is.
My helpful sig has gone because a mod below the administrator gave me an infraction - despite the administrator personally agreeing to it.
If you need any php tips or tricks you can PM me.