2015-12-31 40 views
2

我正在創建一個PHP網站我試圖在用戶在網站上輸入電話號碼時使用Twilio發送消息。目前它只發送一條消息給我在我的代碼中寫的數字。我怎樣才能發送到輸入的號碼?Twilio從網站向多個用戶發送短信

<?php 
require('Twilio.php'); 
// ==== Control Vars ======= 
$strFromNumber = ""; 
$strToNumber = ""; 
$strMsg = "Hey!! "; 
$aryResponse = array(); 

    // set our AccountSid and AuthToken - from www.twilio.com/user/account 
    $AccountSid = ""; 
    $AuthToken = ""; 


    // ini a new Twilio Rest Client 
    $objConnection = new Services_Twilio($AccountSid, $AuthToken); 


    // Send a new outgoinging SMS by POSTing to the SMS resource 

    $bSuccess = $objConnection->account->sms_messages->create(

     $strFromNumber,  // number we are sending from 
     $strToNumber,   // number we are sending to 
     $strMsg   // the sms body 
    ); 



    $aryResponse["SentMsg"] = $strMsg; 
    $aryResponse["Success"] = true; 

    echo json_encode($aryResponse); 
?> 

回答

2

設置$strToNumber到什麼都號碼在人的類型。您可以在form submission得到這個。

如果使用POST請求,您可以將用戶發送到PHP頁面,得到編號:

實例形式:

<form action="[path to your php file].php" method="post"> 
    Phone Number: <input type="tel" name="phone"><br> 
    <input type="submit"> 
</form> 

在[路徑到你的PHP文件] .PHP,把你的代碼上面有,並設置$strToNumber$_POST["number"]

$strToNumber = $_POST["number"]; 

Twilio也可以給的錢,當你發送一條消息,如果你是在步道的帳戶,你MI ght無法發送消息。

+0

$ strToNumber =「$ _POST [」cellphone「];」;喜歡這個? –

+0

@AadeshShah我不做PHP,但'$ strToNumber = $ _POST [「number」];'應該工作。不需要使用引號來包圍代碼。 –

+0

感謝男人它工作非常讚賞 –