The first piece of code appears to be part of building an HTML form.
The second piece of code creates an email using "newsletter.htm" as the body of the email.
If the first piece of code is in "newsletter.htm", then it's not going to be executed until someone receives and views the email, at which point it's too late to be reading your database.
But it sounds like you're executing the second piece of code for each record you retrieve. You don't want to do that. You need to execute the code that builds the email content as if you were building a dynamic webpage (which you would be), and by the time you call the second piece of code the "newsletter.htm" file needs to be finished and closed. DON'T execute (i.e. load in a browser) the "newsletter.htm" file. Create "newsletter.htm" from some other page or process.
While it's possible to create a form in an email body, that generally isn't how you want to be doing it. Create links in the email body back to your website, passing parameters in the URL for your page to act upon.