One last thing to be aware of is to make sure that the encoding of your SMS or PHP file is set to UTF-8. It usually takes no more than one business day to get a link approved, but make sure to do it well in advance of the planned sending. If you want to include links in your messages, you must first go through the whitelisting process on your GatewayAPI profile. There is also a limit of 11 characters (alphanumerical), or 15 numbers (numerical), for Sender IDs, so make sure to keep it at or below this length. Avoid using special characters or symbols as this can result in the message not being sent correctly or the Sender ID being overwritten. 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. Values ('".$phoneNumber."', '".$message."')" Įcho "".$row."".$row."".$row.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. $sql = "INSERT INTO inbox (phone_number, message) In receiving SMS code, we have used MySQL database so that when message will be received then save directly to the database, refresh the page you will have list of messages and phone numbers on your page.ĭie('Connection failed'.$conn->connect_error) If you want to put configuration in your project you may go through environment variables or any other approach. In following php code we have a form where you can add phone number and message only but the configuration for server, we have put it as static for now. Let's write code for sending SMS in PHP first. In GSM Modem Application both Servers are started (first for sending sms, second for receiving sms).GSM Modem Application must be installed on your device.Pre-Requisitesīefore getting started you must have pre-requisites. Before getting started you must have installed GSM Modem android application in your device so that you could send or receive SMS from your mobile device. In this video tutorial we will go step by step to write sample code for sending or receiving FREE SMS in your PHP project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |