Answer the question
In order to leave comments, you need to log in
How to send a message through a PHP form?
<?php
$name = $_POST['name']; // input name
$surname = $_POST['surname']; // input surname
$phone = $_POST['phone']; // input phone
$email = $_POST['email']; // input phone
$message = "Новое сообщение".PHP_EOL."Имя: ".$name.PHP_EOL."Фамилия: ".$surname.PHP_EOL."Телефон: ".$phone.PHP_EOL."Email: ".$email;
define('VK_API_ACCESS_TOKEN', 'токен');
define('VK_API_VERSION', '5.67'); //Используемая версия API
define('VK_API_ENDPOINT', "https://api.vk.com/method/");
//Функция для вызова произвольного метода API
function _vkApi_call($method, $params = array()) {
$params['access_token'] = 'VK_API_ACCESS_TOKEN';
$params['v'] = VK_API_VERSION;
$url = VK_API_ENDPOINT.$method.'?'.http_build_query($params);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($curl);
curl_close($curl);
$response = json_decode($json, true);
return $response['response'];
}
//Функция для вызова messages.send
function vkApi_messagesSend($user_id, $message = array()) {
return _vkApi_call('messages.send', array(
'user_id' => $user_id,
'message' => $message,
));
}
vkApi_messagesSend(идчела, $message);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question