V
V
Valeriu Vodnicear2016-12-01 19:23:47
PHP
Valeriu Vodnicear, 2016-12-01 19:23:47

How to send sms using javascript or php?

Hello everyone)
Are there any ways to send SMS via JavaScript?
Or it is possible through PHP, but still better through JavaScript.
If you know more services, then please recommend those that work at good rates with the CIS countries.
You can even do top services)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2016-12-01
@werty1001

On the node , through the sms.ru service ( You can send SMS to your number for free):

var SMSru = require('sms_ru'),
  sms = new SMSru('api_id');

  sms.sms_send({to: '79112223344',text: 'Текст SMS'}, function(e){
    console.log(e.description);
  });

A
Anton Shamanov, 2016-12-01
@SilenceOfWinter

This is the code from the plugin for cms, but I think you will understand:

/**
     * @param string $to
     * @param string $text
     * @param string $from
     * @return mixed
     */
    public function send($to, $text, $from = null)
    {
        $ch = curl_init("http://sms.ru/sms/send");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);

        $post = array(
            "api_id" => $this->getOption('api_id'),
            "to"     => $to,
            "text"   => $text
        );
        // check from
        if ($from && preg_match("/^[a-z0-9_-]+$/i", $from) && !preg_match('/^[0-9]+$/', $from)) {
            $post['from'] = $from;
        }
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

        $result = curl_exec($ch);
        curl_close($ch);
        $result = explode("\n", $result);

        if ($result[0] == 100) {
            unset($result[0]);
            return $result;
        } else {
            return false;
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question