Found the solution. All I have to do is wrap the email addresses with quotes.
(I need to go through a mailing list and send the mail when the program hits a comma. This is a bit confusing- it works in C++!)
You could just use
explode(",",$list_of_emails) and then loop over the resulting array of email addresses to do your sending.
You could also probably do this in