How do I send an email to multiple recipients? In my plugin, I'm sending an email like this:

$recipients = 'person@example.com';

$email = new EmailModel();
$email-&gt;toEmail = $recipients;
$email-&gt;subject = 'My Email Subject';
$email-&gt;body    = 'My Email Body';

craft()-&gt;email-&gt;sendEmail($email);


Which works great! But when I'm sending to multiple people, the string would look like this...

$recipients = 'person1@example.com, person2@example.com';


... and it generates an error:

Invalid address: person1@example.com, person2@example.com


How do I properly send an email to multiple recipients?
You can loop through a list of your recipients:

// Comma-separated list of recipients
$recipients = 'person1@example.com, person2@example.com';

// Break out recipients into an array
$recipientList = explode( ",", $recipients );

// Create the globally known things about the EmailModel
$email = new EmailModel();
$email-&gt;subject = 'My Email Subject';
$email-&gt;body    = 'My Email Body';

// Loop through each recipient in the recipient list
foreach ( $recipientList as $recipient )
{
    try
    {
        // Add a specific recipient to the email model
        $email-&gt;toEmail = $recipient;

        // Send the email
        craft()-&gt;email-&gt;sendEmail( $email );
    }
    catch ( \Exception $e )
    {
        // Do nothing
        return false;
    }
}