engineerKev
engineerKev

Reputation: 335

Can't get Twilio to send SMS to international #s

I've been working with Twilio to send SMS messages to the potential users of an app. I have figured out how to send messages to US numbers, but sending an SMS to an international mobile user is proving trickier. I'm here to see if anyone can help me figure out what I am doing wrong and to hear any suggestions of ways to address the problem. I've built a simple web page with a drop down menu for the international codes, and input form for the mobile number and a button to send the information to the Twilio server. The code for that looks like this:

<html>
<head><title>Text Me The Link!</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
 //Javascript
 $(function(){
$("#frm").submit(function(e){
e.preventDefault();
$.post("textMeLink.php", $("#frm").serialize(),
function(data){
if(data.sms_sent == 'OK'){
alert("Message Sent");
} else {
alert("Message Not Sent");
}
}, "json");
document.getElementById('frm').reset();
});
    });
   </script>
  </head>
  <body>

 <form id="frm" name="frm" method = "POST">
    <input type="reset" name="ajax" style="display:none"/>
        <h4>Text your phone a download link for our iPhone and Android apps</h4>
                    <select name="code">
                   <?php
                    include "callingCodesV0.php";
                    $countryAndCodes = getCountryDialCodes();
                    foreach($countryAndCodes as $key=>$value){
                        echo "<option value='$value'>$key($value)</option>\n";
                    }

                   ?>
                </select>
    <input type="phone" name="phone" placeholder="Enter Your Mobile Number"/>
    <button type="submit">Get Link</button>
    <div style="display: none; " class="error"/>
</form>

The php file being included, inside the form in the body, is a simple script that takes a json file, which holds all the calling codes, and creates a simple array out of the country code as the key and the dialing code as the element, So it looks like:

 CO(Colombia)=>"+57"

The other PHP(textMeLink.php) file is what handles the phone numbers, and the interaction with the Twilio server. textMeLink.php looks like this:

<?php 

require_once "C:\Users\Kevin\Marco Polo\\twilio-php-master\Services\Twilio.php";
$AccountSid = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$AuthToken = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";

$client = new Services_Twilio($AccountSid, $AuthToken);

$phone=$_POST['phone'];
$code=$_POST['code'];
$phoneAndCode = $code+$phone; 
echo "phoneAndCode";
$sms = $client->account->sms_messages->create(
    "+17327047999",

    $phoneAndCode,

    "Get our app now for iPhone: appstore.com/marcopolo\nGet our app now for Android: ....."
);
$sms_check="OK";
$return_json = '{"sms_sent":"' .$sms_check . '"}';

echo $return_json;
?>

I want to bring emphasis to the lines where I define the variables $phone and $code. As you can see I am trying to concatenate the two variables so that I have a phone number with its respective area code which I can send an SMS to. For some reason however, the concatenation is not working, and when I try to SMS an international number nothing happens. Not even the Twilio log shows the international number I tried to send the SMS to. I am not sure if the error is in the php file that has the html code in it or if the error is in the second php file that handles the phone numbers and deals with Twilio. As I've stated above, any help, suggestions, or pointing out of errors is welcomed. Thank you in advance everyone. :)

Upvotes: 0

Views: 757

Answers (2)

rderoldan1
rderoldan1

Reputation: 4088

I am looking for something similar, the real answer is twilio doesn't support phone calls to Colombia, and only support sms for 2 carriers ("TIGO, Claro")... I send a support email, if I know something I will update my answer

Upvotes: 0

Tim Lytle
Tim Lytle

Reputation: 17624

In PHP you concatenate with the . operator, not the + operator. You're adding the two numbers.

$phoneAndCode = $code+$phone; 

Instead of concatenating:

$phoneAndCode = $code . $phone; 

Upvotes: 1

Related Questions