if(CModule::IncludeModule("sender")){
$params = array(
'EMAIL' => "email@email.ru", //EMAIL
'UNSUBSCRIBE_LIST' => array(1), //Массив id рассылок
);
$unsubscribe = \Bitrix\Sender\Subscription::unsubscribe($params);
die(json_encode($unsubscribe));
}
Alias "CONTACT_ID" matches already existing field "CONTACT_ID" of initial entity "\Bitrix\Sender\PostingRecipient". Please choose another name for alias.
use \Bitrix\Main\Loader;
use \Bitrix\Sender;
/**
* @var string Email пользователя
*/
$email = 'test@efusion.ru';
/**
* @var string Список идентификаторов рассылок для отписки
*/
$unSubscribeList = [
3
];
try
{
if ( !Loader::IncludeModule('sender') )
{
throw new \Exception("Sender module not installed");
}
if ( empty($unSubscribeList) )
{
throw new \Exception("Empty unSubscribeList param");
}
$contactId = Sender\ContactTable::addIfNotExist([
'EMAIL' => $email
]);
if ( !$contactId )
{
throw new \Exception("Contact by email not found and has error when creating");
}
$contact = new Sender\Entity\Contact($contactId);
$data = $contact->getData();
foreach ($data['SUB_LIST'] as $subscriptionId)
{
if ( in_array($subscriptionId, $unSubscribeList) )
{
$contact->unsubscribe($subscriptionId);
}
}
}
catch( \Exception $e )
{
var_dump( $e->getMesage() );
}
use Bitrix\Main\Loader,
Bitrix\Main\Application;
Loader::includeModule('subscribe');
$request = Application::getInstance()->getContext()->getRequest();
if($email = $request->getQuery('email')){
$ob = new CSubscription;
$subscription = CSubscription::GetByEmail($email)->Fetch();
if($subscription){
$arFields = Array("ACTIVE"=>"N");
if($subscription['ID'] && $ob->Update($subscription['ID'], $arFields))
echo "Вы успешно отписались!";
else
echo "Ошибка отписки!";
}else{
echo "Такой пользователь не найден!";
}
}else{
echo 'empty email';
}