This should work. Email me if you don't understand it. I divided the tasks up instead of creating the list of names in the mail function, I created a variable to store the names as a string then used that in the mail function. It is a bit easier to understand that way.
sql = "SELECT name FROM names";
@mysql_select_db($DBName,$link_id);
$result=mysql_query($sql);
// $names = a string of all names returned from SQL statement
$names = ""; // intialize it to be empty;
// store names from database into the a string
// each name is seperated by a comma
while ($line=mysql_fetch_array($result))
{
// if names string is empty, just store the name without a comma
if( $names != "" )
$names .= $line[name];
// else, seperate names with commas
else
$names .= ", " . $line[name];
}
// append names to the body text
$body = "BODY TEXT HERE " . $names . " MORE BODY TEXT AFTER NAMES";
// send the email
MAIL(
"hello@myplace.com",
"TEST SUBJECT HEADER", $names,
"From: $email\nX-Mailer: PHP/" . phpversion()
);
mysql_close($link_id);