![]() This ID can be used as a reference if you need support or similar.Īs a final note, I’d like to share a few things to be aware of when sending SMS messages.įirstly, the “sender” field has some limitations. In the example, we print IDs from the JSON object using “print_r($response)”. If everything goes as planned, you will see the server’s response in your output.įurthermore, we decode the JSON object to access specific information using “json_decode($result, true)”. To see the response from the server, we print “$result” using “print($result)”. Then we close the cURL object with “curl_close($ch)”. This will send the HTTPS request with the specified parameters and store the response from the server in the “$result” variable. We specify the URL where the request should be sent to, set the “Content-Type” to “application/JSON” to tell the server that we are sending a JSON object, and use our API token as the username and no password.Īfter setting up the cURL object, we are ready to execute the request itself by calling “curl_exec($ch)”. Then we set up some parameters for our cURL object using “curl_setopt()”. We start by initializing our cURL object using “curl_init()” and store it in the variable “$ch”. To do this, we use the cURL library built into PHP. Now our JSON object is ready to be sent to the server. In the next line, we leave “recipients” blank because we fill it in the following line, where we use a for loop that takes each recipient and adds them to our recipient array. ![]() Note that if you want to include emojis or special characters, it requires some extra steps, which you can find more information about in our documentation. In the example, I just write “Hello world”. “Message” is of course the content of the SMS. ![]() In the example, it automatically says “ExampleSMS”, but you can enter your own name or the desired Sender ID. For example, if you receive an SMS from your bank, the bank’s name will often be the sender. This is the Sender ID that will be displayed on the recipient’s phone. In the next line we have a JSON object, which is the object that sends information to our server about how the SMS should be sent. In the example we use a couple of test numbers, but you can insert up to 10,000 different recipients here.įirst, enter your country code without any zeros or plus signs in front of it. We have “recipients”, which are the phone numbers the message should be sent to. In the code, we also have details about the content of the message. In the fourth line we have your API token, which is used to identify you and your account. In the third line, we have a variable that contains the URL to our endpoint for sending SMS messages. In the first line, we start our PHP file. If this seems straightforward, you can skip to the section where I execute the script. In this section, I will walk you through each step of the code so you understand what it does and how you can customize it to your specific needs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |