简体   繁体   English

无法让Twilio将短信发送到国际号码

[英]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. 我一直在与Twilio合作,向应用程序的潜在用户发送短信。 I have figured out how to send messages to US numbers, but sending an SMS to an international mobile user is proving trickier. 我已经弄清楚了如何向美国号码发送消息,但是向国际移动用户发送SMS却被证明比较棘手。 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. 我构建了一个简单的网页,其中包含国际代码的下拉菜单,手机号码的输入表单和一个将信息发送到Twilio服务器的按钮。 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: 包含在内部表单中的php文件是一个简单的脚本,该脚本采用一个json文件,该文件保存所有调用代码,并以国家/地区代码为键,以拨号代码为元素创建一个简单数组,因此它看起来像:

 CO(Colombia)=>"+57"

The other PHP(textMeLink.php) file is what handles the phone numbers, and the interaction with the Twilio server. 另一个PHP(textMeLink.php)文件负责处理电话号码以及与Twilio服务器的交互。 textMeLink.php looks like this: textMeLink.php看起来像这样:

<?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. 我想强调定义变量$ phone和$ 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. 如您所见,我正在尝试将两个变量连接起来,以便有一个电话号码及其相应的区号,可以将SMS发送到该电话号码。 For some reason however, the concatenation is not working, and when I try to SMS an international number nothing happens. 但是由于某种原因,该连接无法正常工作,当我尝试通过SMS拨打国际号码时,什么也没发生。 Not even the Twilio log shows the international number I tried to send the SMS to. 甚至Twilio日志也没有显示我尝试向其发送SMS的国际号码。 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. 我不确定错误是否在包含html代码的php文件中,或者错误是否在处理电话号码并处理Twilio的第二个php文件中。 As I've stated above, any help, suggestions, or pointing out of errors is welcomed. 如上所述,我们欢迎您提供任何帮助,建议或指出错误的地方。 Thank you in advance everyone. 预先谢谢大家。 :) :)

In PHP you concatenate with the . 在PHP中,您与串联. operator, not the + operator. 运算符,而不是+运算符。 You're adding the two numbers. 您正在将两个数字相加。

$phoneAndCode = $code+$phone; 

Instead of concatenating: 而不是串联:

$phoneAndCode = $code . $phone; 

我正在寻找类似的东西,真正的答案是twilio不支持打给哥伦比亚的电话,并且仅支持2个运营商(“ TIGO,Claro”)的短信...如果我知道我会发送的信息,我会发送支持电子邮件更新我的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM