Hello I checked your third version and I see that you use repeatedly email functions and you abuse the antiinjection method you can use 1 time the email function and just change the var (the method it will be used, and a for loop for the injection using post vars, I am not using it I just try to help.
good evening.