Integrations / 1С-Битрикс
Sendersy + 1С-Битрикс
1C-Bitrix + Sendersy: hook into OnBeforeMailEvent or POST directly to /v1/emails from your scripts.
1. Install
bash
# 1) Put the file at /local/php_interface/include/sendersy_mailer.php # 2) Wire it up in /local/php_interface/init.php
2. Environment variables
bash
// /bitrix/.settings.php or /local/php_interface/init.php
define('SENDERSY_API_KEY', 'sk_live_...');3. Send an email
php
<?php
// /local/php_interface/include/sendersy_mailer.php
namespace Local\Sendersy;
use Bitrix\Main\EventManager;
use Bitrix\Main\Web\HttpClient;
use Bitrix\Main\Web\Json;
class Mailer
{
public static function register(): void
{
$em = EventManager::getInstance();
$em->addEventHandler('main', 'OnBeforeEventSend', [self::class, 'onBeforeEventSend']);
}
public static function onBeforeEventSend(&$arFields, &$arMessage): bool
{
$apiKey = defined('SENDERSY_API_KEY') ? SENDERSY_API_KEY : '';
if (!$apiKey) return true;
$to = is_array($arFields['EMAIL_TO'] ?? null)
? $arFields['EMAIL_TO']
: [$arFields['EMAIL_TO'] ?? ($arMessage['EMAIL_TO'] ?? '')];
$http = new HttpClient(['socketTimeout' => 15]);
$http->setHeader('Authorization', 'Bearer ' . $apiKey);
$http->setHeader('Content-Type', 'application/json');
$http->post('https://api.sendersy.com/v1/emails', Json::encode([
'from' => $arFields['MESSAGE_FROM'] ?? ($arMessage['EMAIL_FROM'] ?? 'noreply@yourdomain.com'),
'to' => array_filter($to),
'subject' => $arMessage['SUBJECT'] ?? '',
'html' => $arMessage['MESSAGE'] ?? '',
'tags' => [['name' => 'source', 'value' => 'bitrix']],
]));
// Return false to prevent Bitrix from also sending via its built-in mail()
return false;
}
}
// /local/php_interface/init.php
\Local\Sendersy\Mailer::register();