I've had lags in emails being sent by godaddy's smpt.secureserver.net server that will sometimes be half a day or more.
I think it is volume related. I've wasted hours debugging email from godaddy that didn't seem to be sending only to wake up the next morning and see all of my test emails in my inbox. However they do seem to eventually come through.
Are you sending the emails to the same email address each time? Sometimes when it appears email isn't sending it is actually a problem receiving the email because of spam blocking. However based on your description that seems unlikely. It really sounds like an email hosting issue. All the php script can do is send a request to the smtp server to send the email.
If that smtp server is busy it is supposed to queue the email and send it when it can. An overloaded smtp server can malfunction and not send emails. I can't be positive that is what is happening, but it sure sounds like it. If the problem was with the script it would be consistent and either work or not when following the same steps. Inconsistency implies errors with the hosting SMTP server.