Sorry about the late reply, it's been really busy here. I did some debugging and it seems, for some reason your use of the SMTP server seems to be the problem. I wrote a test script to use sendmail instead and it sent it fine. Try switching your gmail config to send using sendmail.
Adrian
Adrian