电子邮件发送限制

时间:2014-10-24 12:40:50

标签: php mysql

我有一个表Groups,其中包含多个组,并且在每个组中都有成员,我想限制,如果一个成员A在两个组中,所以发送一次邮件,而不是两次。

if (isset($_REQUEST['email']))  {

    $admin_email = "someone@example.com";
    $email = $_REQUEST['email'];
    $subject = $_REQUEST['subject'];
    $comment = $_REQUEST['comment'];
    $grp = $_REQUEST['grp'];

    //send email

    echo "Thank you for contacting us!";
    $query = mysqli_query($connection, "SELECT member.email FROM member inner join member_group on member.id = member_group.member_id and member_group.group_id = '$grp'");
    while($data = mysqli_fetch_object($query) ){
        //"<option value='$data->id'>$data->name</option>";
        mail($admin_email, "$subject", $comment, "From:" . $email);
    }
}

1 个答案:

答案 0 :(得分:1)

您可以通过在查询中将SELECT member.email更改为SELECT DISTINCT member.email来完成此操作。

通过这样做,查询将不会检索重复的电子邮件地址。

有关不同here

的更多信息