Move code for getting recipients to a function

This will reduce the code in handle_form making it more readable.