A thing that I have learned about some smtp servers is that if the socket is just closed after it timed out (it doesn't happened with all the servers), then message is not always sent.

After you have queued the email, send a "quit" to the server.


//EDIT: I see that your script has a "quit". In that case I have no idea what is the problem. If the email is queued then it should be sent my the server.