Rus
Eng
Отправка SMS пользователю на Битрикс
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

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

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site