Heres the pseudo code I'd start reswarching were it me.
read all the newlines into an array
foreach($address as $adr) {
$to.=",$adr";
}
you just need to get the to part of mail into a comma seperated list of recipients. I can already see a problem with the first entry to the list in my pseudo code but I hope this gives you a direction to follow at least 🙂
Nick