2016-11-30 92 views
0

我通過使用PHP腳本的sms api發送消息。 短信發送成功,但我在我的消息中遇到了問題。 Php Script只發送「ThankYou」留言不會發送到手機。從PHP腳本發送短信

$message1="ThankYou '$email' you are succesfully booked your service.Your booking details Booking Date = '$date'Booking Location='$location'"; 

我的PHP腳本:

<?php 

require 'PHPMailer/PHPMailerAutoload.php'; 
require "init.php"; 
    $email=$_POST['email']; 
    $bikeno=$_POST['bikeno']; 
    $location=$_POST['location']; 
    $date=$_POST['date']; 
    $mobileno=$_POST['mobileno']; 
    $sql="select * from book_order where location ='".$location."' and date ='".$date."';"; 
    $result=mysqli_query($con,$sql); 
    $response =array(); 
    if(mysqli_num_rows($result)>=20) 
    { 
    $code="reg_failed"; 
    $message="Sorry For that Selected Date or Service Centre Is also Booked try with another Date or Service centre"; 
array_push($response,array("code"=>$code,"message"=>$message)); 
echo json_encode($response);  
    } 
    else { 
$sql="insert into book_order(email,bikeno,location,date,mobileno) values ('".$email."','".$bikeno."','".$location."','".$date."','".$mobileno."');"; 
$result=mysqli_query($con,$sql); 
$code="reg_success"; 
$message="Thanks for choose use for serve you better."; 
array_push($response,array("code"=>$code, "message"=>$message)); 
echo json_encode($response); 
    if($sql) 
{ 
$message1="ThankYou '$email' you are succesfully booked your service.Your   booking details Booking Date = '$date'Booking Location='$location'"; 


    $URL = "http://ptms.bulksmshyderabad.in/API/sms.php?username=xxxx&password=xxxx&from=YAMAHA&to=$mobileno&msg=$message1&type=1&dnd_check=0"; 
    $ch = curl_init(); 


curl_setopt($ch, CURLOPT_URL, $URL); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    $result=curl_exec($ch); 


    }  

    } 


    mysqli_close($con); 
    ?> 
+0

$ message1 =「ThankYo +'$ email'+ you + are + succesfully + booked + your + service +。+您的預訂+詳細信息+預訂+日期+ = +'$ date'+預訂+位置+ = + $位置「+」; –

回答

1

你必須在url無效字符(即')。 SMS服務器無法正確解析您的SMS消息。使用下面的代碼使查詢字符串對於GET請求安全/有效。

$message1 = "..."; // Your original message 
$safeMessage = urlencode($message1); 

當然,你需要$URL指定值時使用$safeMessage

其他注意事項:

  • 請考慮在網址中刪除您從問題敏感的憑據,即真實的用戶名和密碼。
  • 您的curl請求正在形成POST請求,但GET請求似乎已經足夠,因爲API可以從url中獲取所有信息。