Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");?>
- <?
- // Ваш ключ доступа к API (из Личного Кабинета)
- $api_key = "";
- // Данные о новом контакте
- $user_email = $_POST["email"];
- //$user_name = iconv('cp1251', 'utf-8', "Василий Иванович Чапаев");
- $user_lists = "16357969";
- $user_tag = urlencode("Site subscriber");
- // Создаём POST-запрос
- $POST = array (
- 'api_key' => $api_key,
- 'list_ids' => $user_lists,
- 'fields[email]' => $user_email,
- //'fields[Name]' => $user_name,
- 'tags' => $user_tag
- );
- // Устанавливаем соединение
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $POST);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_URL, 'https://api.unisender.com/ru/api/subscribe?format=json');
- $result = curl_exec($ch);
- if ($result) {
- // Раскодируем ответ API-сервера
- $jsonObj = json_decode($result);
- if(null===$jsonObj) {
- // Ошибка в полученном ответе
- echo "Invalid JSON";
- }
- elseif(!empty($jsonObj->error)) {
- // Ошибка добавления пользователя
- echo "An error occured: " . $jsonObj->error . "(code: " . $jsonObj->code . ")";
- } else {
- // Новый пользователь успешно добавлен
- echo "Added. ID is " . $jsonObj->result->person_id;
- }
- } else {
- // Ошибка соединения с API-сервером
- echo "API access error";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement