Simple PHP check

Hi guys, I cannot get this script to work. Can you please tell me where i went wrong?

<?php require_once("routeros_api.class.php"); /**** Function to send SMS via Mikrotik SMS Gateway ***/ function send_sms($number, $text) { global $smsgw; $API = new routeros_api(); if ($API->connect("192.168.88.1", "admin", "admin")) { \ \ $API->comm("tool sms send usb2 channel=3 phone-number=1234 message=test"); } else { echo "error"; return "could not connect to mikrotik gateway"; } \ \ } send_sms("1234", "test"); ?>

The API protocol uses a very different syntax from the shell.

Using the client from my signature, you can use a shell-like syntax… the main difference being that you must explicitly specify ALL argument names. In your case, that would be:

<?php
namespace PEAR2\Net\RouterOS;
require_once 'PEAR2_Net_RouterOS-1.0.0b3.phar';

/**** Function to send SMS via Mikrotik SMS Gateway ***/
function send_sms($number, $text) {
    global $smsgw;
    try {
        $API = new Client("192.168.88.1", "admin", "admin");

        $API->sendSync(new Request("/tool sms send port=usb2 channel=3 phone-number=1234 message=test"));
    } catch (Exception $e) {
        echo "error";
        return "could not connect to mikrotik gateway";
    }
}

send_sms("1234", "test"); 

And if you want to use your current client, you’ll have to follow the API syntax, per the spec.

(Side note: On my RouterOS, the phone number is specified with the “dst” argument, not the “phone-number” argument… what RouterOS version are you using?)