PHP mailer multiple address

PhpPhpmailer

Php Problem Overview


> Possible Duplicate:
> PHPMailer AddAddress()

Here is my code.

require('class.phpmailer.php');
$mail = new PHPMailer();

$email = '[email protected], [email protected], [email protected]';

$sendmail = "$email";

$mail->AddAddress($sendmail,"Subject");
$mail->Subject = "Subject"; 
$mail->Body    = $content;		
	
if(!$mail->Send()) { # sending mail failed
	$msg="<span style=\"font-size: 16px; background: #C7EAF3; color:#333333; display: block; padding: 3px;\">Unknown Error has Occured. Please try again Later.</span>";
}
else {
	$msg="<span style=\"font-size: 16px; background: #C7EAF3; color:#333333; display: block; padding: 3px;\">Your Message has been sent. We'll keep in touch with you soon.</span>";
} 	

}

The Problem
if $email value is only 1. It will send. But multiple don't send. What should I do for this. I know that in mail function you have to separate multiple emails by comma. But not working in phpmailer.

Php Solutions


Solution 1 - Php

You need to call the AddAddress method once for every recipient. Like so:

$mail->AddAddress('[email protected]', 'Person One');
$mail->AddAddress('[email protected]', 'Person Two');
// ..

Better yet, add them as Carbon Copy recipients.

$mail->AddCC('[email protected]', 'Person One');
$mail->AddCC('[email protected]', 'Person Two');
// ..

To make things easy, you should loop through an array to do this.

$recipients = array(
   '[email protected]' => 'Person One',
   '[email protected]' => 'Person Two',
   // ..
);
foreach($recipients as $email => $name)
{
   $mail->AddCC($email, $name);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJorgeView Question on Stackoverflow
Solution 1 - PhpAlan OrozcoView Answer on Stackoverflow