Im working on an application that will let me send group emails using PHP.
All the emails are going to be stored in a database.. I expect to have a lot of
email addresses, maybe thousands. Ive used the MAIL function before to send individual emails but i never tried to send a group email...

I just wanted to know if the way to do it is: looping through all the emails in the database and use the mail function on each one of them ? wouldn't they all go to the junk mail because it's an auto generated email ? and if so, how does all the other mailing group application works ?

also, i want the email to be an HTML/CSS email. I did it before, but this time, it suppose to look like a newsletter, and some of the template information that's going to be in the newsletter will have to come from a db. the tricky part is, i assume that the template will change from time to time, i was thinking about creating html templates and open them using php fopen, copy all the information to a variable and use the variable as the message body, the only problem is, that i want the html template to include some PHP in order to retrieve some information from the database, is there a way to do that ? or the only way is to echo the html directly into a variable and append php requests to it where necessary ?