I'm currently attempting to pull information from a database which is used to populate an email function. I'm trying to get it to send a number of emails equal to the number of email addresses stored in the database. (One row can have multiple email addresses stored in the same column, delimited by a comma).
(Example - [email protected], [email protected])
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if (strpos($row["mailcontacts"], ',') !== false) {
$contact = explode(',', $row["mailcontacts"]);
//print_r($contact);
foreach ($contact as &$toaddress) {
$mail->addAddress($toaddress);
}}
The functionality I want works for the first row that matches. It sends one email for the first row to dave and bob. However, any further rows the email gets sent to the contacts which it's already been sent to. Essentially Dave and Bob will be included on every email.
I've tried to unset each of the different variables in different places but I think this isn't where the issue is. If I use print_r($toaddress) as commented out it provides arrays for each row as needed.
whileloop. Wait till the loop ends and all addresses are added, then send the mail after the loop.