// 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. "'");
这就是我现在正在使用它并根据列表中有多少用户发送大量电子邮件,但仅发送给被删除的用户,这是一个非常奇怪的错误。也许我应该使用限制或实际抓住目标用户的数量?提前谢谢。
答案 0 :(得分:1)
看起来你的问题(除了这段代码可以使用主要重构的事实)是在while循环中:
while($ev5 = mysql_fetch_array($the_result_member)){
$user_emails_member = $ev5["user_email"];
$email_list_member .= "".$user_emails_member.","; // Problem
}
为foreach循环中找到的每个用户附加email_list_member
。尝试分配值而不是附加值。
- 更新 -
呃,不想进入重构,但试试这个(未经测试):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) . ")";
}
答案 1 :(得分:0)
目前还不是很清楚你想要什么,也不知道你在做什么,但是对SELECT
中的每个元素运行$_POST['members_cbox']
查询似乎不是一个好主意。 DELETE
语句也是如此。
算法应该是:
where user_id in(...)
语法最重要的是,至少在3个方法/函数中模块化该代码!