0

I want to send each email a specific message, but the look is not working as expected, because the first email address receives her corresponding message, but the second email address receives two messages (the one for the first and the one for the second email in the list), and the third email receives three emails, each email with the message for each email.

This is my code:

$messages = array(
    'x1@gmail.com'=>'message for X1',
    'x2@gmail.com'=>'message for X2',
    'x3@gmail.com'=>'message for X3'
);

foreach ($messages as $key => $value) {
    $mail->addAddress($key);
    $mail->Subject = $value;
    $mail->send();
}

I tried unset($razones[$key]); before the loop ends, so the item is extracted from the array before continues, but still the output is not working.

This is what I get:

X1 receives 3 mails: message for X1 message for X2 message for X3

X2 receives 2 mails: message for X2 message for X3

X3 receives 1 mail: message for X3

The intended result I think is pretty obvious:

X1 receives 1 email: message for X1

X2 receives 1 email: message for X2

X3 receives 1 email: message for X3

I know that there is something silly not working in my logic, and staring right at my face, but I cannot see it after many hours of trying on my own.

I'll appreciate any help!

Rosamunda
  • 14,620
  • 10
  • 40
  • 70

0 Answers0