The last notes
All English-language materials have been translated fully automatically using the Google service
In 2019, 1C-Bitrix
has a built-in SMS messaging mechanism, but at the moment there are only three services available: sms.ru, sms assistant and twilio
. This article will show you how you can send SMS messages through other services if, for some reason, the above are not suitable for you.
// Register a user registration event handler
AddEventHandler ("main", "OnBeforeUserRegister", Array ("EventHunter", "OnBeforeUserRegisterHandler"));
class EventHunter {
// Directly the handler that accepts user fields
function OnBeforeUserRegisterHandler (& $ arFields) {
// If registration is successful and the field is filled
if (($ arFields ['USER_ID']> 0) && (isset ($ arFields ['PERSONAL_PHONE']))) {
// Form a message
$ message = "Welcome to the site!";
// Collect the fields
$ fields = array (
'login' => SMSC_LOGIN, // Your login SMS-center
'psw' => SMSC_PASS, // Your SMS-center password
'phones' => $ arFields ['PERSONAL_PHONE'], // The Phone field filled in by the user
'mes' => $ message, // The message to be sent
'charset' => LANG_CHARSET, // Site encoding
);
// Form the URL for sending the request
$ url = 'https://smsc.ru/sys/send.php?' ... http_build_query ($ fields);
// Initialize the session
$ curl = curl_init ($ url);
curl_setopt ($ curl, CURLOPT_HEADER, 1); // Read the title
curl_setopt ($ curl, CURLOPT_NOBODY, 1); // Read header without body
curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // Do not display
// Execute the request
$ result = curl_exec ($ curl);
// End session
curl_close ($ curl);
}
}
}
Reprint of material:
Comments