Unfortunately email servers are notoriously unreliable. That is why we strongly recommend creating a database back end to manage orders and not rely entirely on the email receipt delivery.
You could ask you hosting provider if they have an SMTP error log to see if there are any errors you could correct, but it is possible that you are on a shared server and during large volume and server load an SMTP email server will not send out some emails properly. Maybe another user on that server was doing an email blast to thousands of people and the SMTP server got hung up.
In all likelihood there is nothing wrong with your code that could be corrected. The only solution might be to move to a dedicated server with a dedicated SMTP server.