File upload does not complete when there is "send email code" in "on after insert"

Hi, I am using a form to insert data into the db, including a file upload file. When this is the only thing going on in the application it is working fine. But I would like to get a notification by email every time the form is submitted.

For this I use a standard code for sending email in the event “onAfterInsert”. The email is being sent when the form is submitted, but the form does not actually insert any data. Remove the email notification and the form is working fine again.

So, the conclusion is that there is something going on between clicking the submit button in the form and the email notification being sent. Both these steps are working fine individually, but not together.

Does anybody have any experience with this issue?

After entering the record to the database with the attachment, redirects to a blank type app where you validate the correct entry in the database. And in this blank app you must place the code to send the email.