As attachement or in body of email?
Well both similar so here is overview
get query restrictions from user (ie for what dates (date range), by what user criteria)
build query string
run query and get results
either create a text file (fopen, fwrite, fclose) or echo results to a string that is the body of the email.
attach file (if required)
send email