PHP发送SMS API

时间:2014-05-23 20:54:45

标签: php sql curl sms

查看我的PHP代码中的以下代码段:

function SMS(){

$msg1="".$bookingNo."\n".$guestName."\n".$guestEmail."\n".$guestPhone."\n".$guestAddress."\n".$place."\n".$account."\n".$reportingDate."\n".$reportingTime."";   
file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}

问题是这个http链接在浏览器窗口上运行时成功发送短信, 在&message=中有一些虚拟文字。

但是当我在$msg1&内部分配所有已定义和测试的变量时在同一个网址中调用它。

Woosh,它显示NO ERROR&在调用此函数时没有任何反应。没有短信。

我想知道哪里错了?

由于

更新代码:

function SMS(){

$bookingNo=$_REQUEST['bookingNo'];
$guestName=$_REQUEST['guestName'];
$guestEmail=$_REQUEST['guestEmail'];
$guestPhone=$_REQUEST['guestPhone'];
$guestAddress=$_REQUEST['guestAddress'];
$place=$_REQUEST['place'];
$account=$_REQUEST['account'];
$reportingDate=$_REQUEST['reportingDate'];
$reportingTime=$_REQUEST['reportingTime'];

$msg1="".$bookingNo."\n".$guestName."\n".$guestEmail."\n".$guestPhone."\n".$guestAddress."\n".$place."\n".$account."\n".$reportingDate."\n".$reportingTime."";
file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}



}

SMStoDriver();

2 个答案:

答案 0 :(得分:2)

网址中不允许使用换行符。您需要对消息进行编码:

function SMS(){

    $bookingNo=$_REQUEST['bookingNo'];
    $guestName=$_REQUEST['guestName'];
    $guestEmail=$_REQUEST['guestEmail'];
    $guestPhone=$_REQUEST['guestPhone'];
    $guestAddress=$_REQUEST['guestAddress'];
    $place=$_REQUEST['place'];
    $account=$_REQUEST['account'];
    $reportingDate=$_REQUEST['reportingDate'];
    $reportingTime=$_REQUEST['reportingTime'];
    $msg1=urlencode("Booking No: $bookingNo\nName: $guestName\n Email: $guestEmail\nPhone: $guestPhone\nAddress: $guestAddress\nPlace: $place\nAccount: $account\nDate: $reportingDate\nTime: $reportingTime");
    file('http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message='.$msg1.'');}
}

答案 1 :(得分:0)

您似乎正在尝试使用file方法发出网络请求。也许您的PHP ini配置为not allow file I/O requests to URLs

最好使用cURL

等方式发出网络请求
$curl = curl_init();

curl_setopt_array($curl, array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => 'http://sms.xxxxxxxxxxxxx.co.in/api/webxxxx.php?workingkey=76565xxxxxx&sender=ILUVU&to=9897xxxxxxx&message=test',
    ));

$resp = curl_exec($curl);

curl_close($curl);