How can I send multiple emails in PHP Mailer

1

I am using the PHP Mailer library, to send emails, in this case if you send them, but only to a single email address, and I want, through an array that brings me certain emails from the bd and can send to each of them. This is the code of the library where the recipient goes.

$mail->addAddress('yourusermail.com');

I can not add for example:

    $mail->addAddress('yourusermail.com', '[email protected]', '[email protected]');
    
asked by Jonathan 05.08.2017 в 22:21
source

2 answers

3

You can repeat the AddAddress method as many times as you need or use the instruction within a cycle:


  $mail->AddAddress('[email protected]');
  $mail->AddAddress('[email protected]');
  $mail->AddAddress('[email protected]');
    
answered by 05.08.2017 в 22:33
2

You could make a for to repeat the times of the length of your arrangement:

$emails = array("yourusermail", "[email protected]", "[email protected]");

for($i = 0; $i < count($cars); $i++) {
    $mail->AddAddress($emails[$i]);
    echo $emails[$i];
}
    
answered by 03.11.2018 в 16:19