PHPMailer AddAddress()

kmunky picture kmunky · Nov 20, 2009 · Viewed 113.6k times · Source

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 = "[email protected],[email protected],[email protected]";
$obj->AddAddress($to);

but with no success. Any help will be appreciated.

Answer

doamnaT picture doamnaT · Nov 20, 2009

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('[email protected]', 'First Name');
$mailer->AddAddress('[email protected]', 'Second Name');
$mailer->AddAddress('[email protected]', 'Third Name');

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