简体   繁体   中英

PHP SEND SMS API

have a look at below snippet inside my PHP code :

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.'');}

The problem is this that this http link is sending SMS successfully when run on browser window, with some dummy text in &message= .

But when I am assigning all defined and tested variables inside $msg1 & calling it in same url.

Woosh, it shows NO ERROR & nothing happens, on calling this function. NO SMS.

I wonder where m wrong ?

Thanks

UPDATED CODE :

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();

Newline characters are not allowed in URLs. You need to encode the message:

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.'');}
}

It looks like you are trying to use the file method to make the web request. Perhaps your PHP ini is configured to not allow file I/O requests to URLs .

You would be better off making the web request with something like 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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