By adding that code at the first line, that means the email will be sent before the verification takes place.
you need to have the UE code after the code on that file that verifies the captcha.
you do know that there is a webassist captcha validation that can be used, right?
By using the webassist captcha, you can have the validation and UE behavior on the same form page so you wont run into these issues.