PHPMailer AddAddress()


Question

I don't know how the data should be formatted for AddAddress PHPMailer function; I need the email to be sent to multiple recipients so I tried

$to = "me@domain.com,you@domain.net,she@domain.it";
$obj->AddAddress($to);

but with no success. Any help will be appreciated.

1
33
12/25/2015 1:25:31 PM

Accepted Answer

You need to call the AddAddress function once for each E-Mail address you want to send to. There are only two arguments for this function: recipient_email_address and recipient_name. The recipient name is optional and will not be used if not present.

$mailer->AddAddress('recipient1@domain.com', 'First Name');
$mailer->AddAddress('recipient2@domain.com', 'Second Name');
$mailer->AddAddress('recipient3@domain.com', 'Third Name');

You could use an array to store the recipients and then use a for loop. I hope it helps.

66
6/30/2014 9:23:15 AM

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

$mail->AddAddress('person1@domain.com', 'Person One');
$mail->AddAddress('person2@domain.com', 'Person Two');
// ..

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

$recipients = array(
   'person1@domain.com' => 'Person One',
   'person2@domain.com' => 'Person Two',
   // ..
);
foreach($recipients as $email => $name)
{
   $mail->AddAddress($email, $name);
}

Better yet, add them as Carbon Copy recipients.

$mail->AddCC('person1@domain.com', 'Person One');
$mail->AddCC('person2@domain.com', 'Person Two');
// ..

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

$recipients = array(
   'person1@domain.com' => 'Person One',
   'person2@domain.com' => 'Person Two',
   // ..
);
foreach($recipients as $email => $name)
{
   $mail->AddCC($email, $name);
}

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon