Please UseCodeTags . Code is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
If it works in the local system, there's a chance that one of the remote mail servers is rejecting the mail. See if you can get a look at the logs for those servers.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.