Answer the question
In order to leave comments, you need to log in
How to make a VKontakte newsletter from the community?
Hello, I need a script that will send out mailings on behalf of the community to everyone who has ever written to the community in a PM (if this is not possible, then since the script was launched, they have ever written to a bot).
I found only such a script, but it only sends out to certain users, but to everyone who has ever written to the community in PM.
<?php
// VK API messages.send пример отправка - рассылка сообщений пользователям от имени группы через php
// Токен сообщества или группы
$token ='токен группы';
if(isset($_POST['send_message'])){
if(empty($_POST['user_ids'])){echo'Хотябы один ID пользователя для рассылки';}
if(empty($_POST['message'])){echo'Не введено сообщение рассылки';}
else{
$query = file_get_contents("https://api.vk.com/method/messages.send?user_ids=".urlencode($_POST['user_ids'])."&message=".urlencode($_POST['message'])."&access_token=".$token);
$result = json_decode($query,true);
print_r($result);
}
}
// Чтобы отправлять сообщения не на id а а домен под тип vk.com/rrrrrrr нужно использовать вместо user_ids domain
// ставьте лайки и подписывайтесь если годно, код будет где то в видео удачи!
?>
Answer the question
In order to leave comments, you need to log in
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);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question