1C-Bitrix Integration with Email Marketing Services
The built-in Bitrix mailing module (bitrix:sender) handles basic tasks but falls short of specialized services in email deliverability, template editing, A/B testing, and analytics. Integrating with external ESPs (Email Service Providers) — Mailchimp, SendPulse, UniSender, eSputnik — enables using the capabilities of the service while keeping data in Bitrix.
General integration architecture
Regardless of the specific service, the integration addresses three tasks:
- Subscriber export — site users who have subscribed are added to the mailing service list.
- Segment synchronization — Bitrix user groups (buyers, inactive, VIP) correspond to tags or lists in the ESP.
- Reverse synchronization — unsubscribing in the mailing service updates the subscriber status in Bitrix.
Managing subscriptions in Bitrix
Subscriptions are stored in the following tables:
-
b_subscribe— mailing categories. -
b_subscribe_email— subscriber addresses. -
b_user_subscribe— mapping of users to categories.
The subscribe event is OnSubscribeSubscribe (module subscribe). Unsubscribe event: OnSubscribeUnSubscribe. Subscribe to these events to synchronize with the ESP.
Passing a subscriber to the ESP
AddEventHandler('subscribe', 'OnSubscribeSubscribe', function($subscribeId, $email, $fields) {
$espClient = new EspApiClient();
$user = CUser::GetByLogin($email)->Fetch();
$subscriberData = [
'email' => $email,
'first_name' => $user['NAME'] ?? '',
'last_name' => $user['LAST_NAME'] ?? '',
'tags' => getSubscriberTags($user),
'source' => 'bitrix_subscribe',
];
$espClient->addOrUpdateContact($subscriberData);
});
function getSubscriberTags(array $user): array {
$tags = ['site-subscriber'];
// Add tags based on purchase history
if (hasOrders($user['ID'])) $tags[] = 'buyer';
if (isVipClient($user['ID'])) $tags[] = 'vip';
return $tags;
}
Behavioral segmentation
The value of the integration lies in passing site behavioral data to the mailing service for trigger-based scenarios:
| Event in Bitrix | Action in ESP |
|---|---|
| Added item to cart, did not purchase | Add to "Abandoned Cart" segment, start sequence |
| Placed an order | Add to "Buyers" segment, start welcome series |
| No activity for 90 days | Add to "Inactive" segment, start reactivation |
| Birthday in 7 days | Add to "Birthday" segment, send personal offer |
Events are tracked via OnSaleOrderSaved, OnSaleBasketSaved handlers, and agents for activity checks.
Reverse unsubscribe synchronization
The ESP sends unsubscribe notifications via webhooks. Accept the webhook at a dedicated URL (/bitrix/tools/esp_webhook.php) and update the status in Bitrix:
// esp_webhook.php
$payload = json_decode(file_get_contents('php://input'), true);
$email = $payload['email'] ?? '';
$event = $payload['event'] ?? ''; // 'unsubscribe', 'spam_complaint'
if (in_array($event, ['unsubscribe', 'spam_complaint'])) {
// Unsubscribe in Bitrix
$subscribeEmail = CSubscribeEmail::GetByEmail($email)->Fetch();
if ($subscribeEmail) {
CSubscribeEmail::Update($subscribeEmail['ID'], ['CONFIRMED' => 'N']);
}
}
Transactional emails
Order emails (confirmation, status updates) can be sent via the ESP instead of the Bitrix built-in mail server — for better deliverability and analytics. Override the mail event handler in bitrix/php_interface/init.php:
AddEventHandler('main', 'OnBeforeEventSend', function(&$eventFields, &$template) {
// Intercept the email and send it via the ESP
$esp = new EspTransactionalSender();
$esp->send($eventFields['EMAIL'], $template['SUBJECT'], $template['BODY_HTML']);
return false; // do not send via the built-in SMTP
});
| Task | Effort |
|---|---|
| Subscriber export + event handlers | 4–6 h |
| Behavioral segmentation | 6–10 h |
| Reverse unsubscribe synchronization | 3–4 h |
| Transactional emails via ESP | 4–6 h |







