0
    // Show the members that are in the Database
    $query = "SELECT user_id, membership_id, user_email, first_name, last_name, approved        FROM vintage_user ORDER BY user_id ";
$result = mysql_query( $query, $mysql )
or die( mysql_error() );

if (mysql_num_rows($result) > 0){
$members = "<ul class='theApprovalList'>";
while($ev = mysql_fetch_array($result)){
    $row_id = $ev['user_id'];
    $first_name = $ev["first_name"];
    $last_name = $ev["last_name"];
    $email_member = $ev["user_email"];
    $membership_id = $ev["membership_id"];
    $members .= "<li><p>Members Name: ".$first_name." ".$last_name."</p></br>    <p>Member's Email: ".$email_member."</p></br><p>Membership ID: ".$membership_id."</p></li>";
    $members .= "<li><form action=".$myPage."  method=\"post\"><input class=\"event_item_box\"  id=".$row_id." type=\"checkbox\"  name=members_cbox[] value=".$row_id."></li><p  class=\"event_item_border\"><p/>";


if (sizeof($_POST['members_cbox'])) {
foreach($_POST['members_cbox'] AS $row_id ) { 
                $email_query_member = "SELECT user_email FROM `vintage_user` WHERE user_id='" .$row_id. "'";
            $the_result_member = mysql_query( $email_query_member, $mysql )
                or die( mysql_error() );
            if (mysql_num_rows($the_result_member)){
                $email_list_member = "";
                while($ev5 = mysql_fetch_array($the_result_member)){
                    $user_emails_member = $ev5["user_email"];
                    $email_list_member .= "".$user_emails_member.",";
                }
                mysql_free_result($the_result_member);
            }
        $to2 = $email_list_member;
        $from = "";
        $subject2 ="";
        $headers = "From: {$from}" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        mail($to2, $from, $subject2, $headers);
        mysql_query("DELETE FROM `vintage_user` WHERE user_id='" .$row_id. "'");

这就是我现在使用的,它根据列表中有多少用户发送大量电子邮件,但只发送给被删除的用户,这是一个非常奇怪的错误。也许我应该使用限制或实际抓住目标用户的数量?提前致谢。

4

2 回答 2

1

看起来您的问题(除了此代码可能使用主要重构的事实)在 while 循环中:

while($ev5 = mysql_fetch_array($the_result_member)){
    $user_emails_member = $ev5["user_email"];
    $email_list_member .= "".$user_emails_member.","; // Problem
}

对于email_list_member在 foreach 循环中找到的每个用户,都将附加 。尝试只分配值而不是附加它。

- 更新 -

呃,不想进行重构,但试试这个(未经测试):

if (sizeof($_POST['members_cbox'])) {

    $membersToDelete = $_POST['members_cbox'];

    // If this doesn't work
    $membersToDelete = array_map('mysql_real_escape_string', $membersToDelete);

    // Use this
    $membersToDelete = array_map('intval', $membersToDelete);

    $email_query_member = "SELECT user_email FROM `vintage_user` WHERE user_id IN (" . implode(',' $membersToDelete) . ")";

    $the_result_member = mysql_query( $email_query_member, $mysql ) or die( mysql_error() );

    while($ev5 = mysql_fetch_array($the_result_member)) {

        $user_emails_member = $ev5["user_email"];           

        $to2 = $user_emails_member;
        $from = "";
        $subject2 ="";
        $headers = "From: {$from}" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        mail($to2, $from, $subject2, $headers);
    }

    mysql_query("DELETE FROM `vintage_user` WHERE user_id IN (" . implode(',' $membersToDelete) . ")";
}
于 2012-04-11T18:21:00.430 回答
0

目前尚不清楚您想要什么或在做什么,但是对 SELECT每个元素运行查询$_POST['members_cbox']似乎不是一个好主意。声明也是DELETE如此。

算法应该是:

  1. where user_id in(...)使用语法获取要从数据库中删除的所有成员
  2. 向他们每个人发送电子邮件
  3. 使用与以前类似的语法删除所有这些

最重要的是,至少将代码模块化为 3 个方法/函数!

于 2012-04-11T17:39:09.380 回答