I have a custom php eCommerce website.
In which i have two tables named order & users.
Now i need to send email to those users whose order state is 0.
user id is stored in users table.
Here is my php code :
<?php
   $query = mysqli_query($link, "SELECT * FROM dg_order WHERE state=0");
    while ($row   = mysqli_fetch_assoc($query)) {
        $uid   = $row['uid'];
        $users = mysqli_query($link, "SELECT * FROM dg_users WHERE uid='$uid'");
        while ($rw    = mysqli_fetch_assoc($users)) {
            $em = $rw['email'];
            mail($em, $subject, $message, $headers);
        }
    }
But it sends email to one user several times according to number of unpaid orders. How can i send email to those who have unpaid orders only once and also how can I send list of unpaid orders in email too?
 
     
     
    