Skip to content

Instantly share code, notes, and snippets.

@mtangoo
Created July 4, 2019 11:37
Show Gist options
  • Select an option

  • Save mtangoo/977b357bfd5a5a420278949e448e22d3 to your computer and use it in GitHub Desktop.

Select an option

Save mtangoo/977b357bfd5a5a420278949e448e22d3 to your computer and use it in GitHub Desktop.

Revisions

  1. mtangoo created this gist Jul 4, 2019.
    49 changes: 49 additions & 0 deletions sms-sender.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // Make sure that you are in same web directory as your project root
    // Install guzzle with composer
    // composer require guzzlehttp/guzzle:~6.0

    <?php
    require_once('vendor/autoload.php'); //don't add this if you are using a framework


    use GuzzleHttp\Client;
    use GuzzleHttp\Psr7\Request;

    //Uploa successfully
    $mobile = ''; //your phone number
    $name = ''; //Your name
    $message = "Dear {$name}, your account just logged in. If not you please report it immediately!";

    $client = new Client([ 'base_uri' => 'http://127.0.0.1:9501',]);

    try {
    $response = $client->request('GET', '/api', [
    'query' => [
    'action' => 'sendmessage',
    'username' => 'admin',
    'password' => 'abc123',
    'recipient' => $mobile,
    'messagetype' => 'SMS:TEXT',
    'messagedata' => $message,
    ]
    ]);
    $code = $response->getStatusCode();
    if ($code == 200) {
    echo json_encode([
    'success' => true,
    'message' => 'Successfully logged in',
    ]);
    exit();
    } else {
    echo json_encode([
    'success' => false,
    'message' => "failed with error code {$code}",
    ]);
    }
    } catch (\Exception $e) {
    echo json_encode([
    'success' => false,
    'message' => $e->getMessage(),
    ]);
    }