Send an SMS Message with PHP

Note:

Before you can get started, you need the following already set up:

  • Set all SMS API configuration settings.
  • PHP 7.3.0 or later and a familiarity with how to create a new file.
  • cURL 7.61.0 or later installed

This script will enable you to send an SMS message using PHP and the Sinch SMS API.

Steps:
  1. Set up your PHP file.
  2. Send your first SMS message.

Set up your PHP file

Create a file (example: send_sms.php) and add the supplied sample code.

Fill in your parameters

  1. Assign your values found in the your Sinch Customer Dashboard to the following parameters:
    Copy
    Copied
    $service_plan_id = "YOUR_servicePlanId";
    $bearer_token = "YOUR_API_token";
    
    //Any phone number assigned to your API
    $send_from = "YOUR_Sinch_virtual_number";
    //May be several, separate with a comma ,
    $recipient_phone_numbers = "recipient_phone_numbers";
    $message = "Test message to {$recipient_phone_numbers} from {$send_from}";

    Double check that the region is correct on your base URL. Learn more about regional options here.

  2. Now, in the string portions in the code below, write your message:
    Copy
    Copied
    $message = "Test message to {$recipient_phone_numbers} from {$send_from}";
  3. That's it! Just copy the rest of the script into your file, save, and you'll be sending messages in no time.

Send your first SMS message

Execute the code and send your test SMS message with the command below:

Copy
Copied
php send_sms.php

Additional resources

Visit our API specification to test more endpoints.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.