function send_all_message($users, $message, $attach){
$get_params = http_build_query(array('message'=>$message,'attachment'=>$attach,'user_ids'=>$users,'access_token'=>$GLOBALS[token],'v'=>'5.80'));
$send = file_get_contents('https://api.vk.com/method/messages.send?'.$get_params);
if(preg_match('/error/iu',$send)){return 1;}else{return 0;}
}
$users = mysql_query("SELECT * FROM `users`"); // на свой вкус и цвет, дал тебе основу
$count = 0;
$users_list = '';
while($users_info = mysql_fetch_array($users))
{
$count++;
if($count < 100) { $users_list = $users_list.$users_info['login'].','; }
if($count == 100) {
$users_list = $users_list.$users_info['login'];
$count = 0;
send_all_message($users_list, $spam, $attach);
$users_list = '';
}
}
if($users_list) {
$last_users = substr($users_list, 0, -1);
send_all_message($last_users, $spam, $attach);
}