从PHP脚本发送短信

问题描述:

我通过使用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'+预订+位置+ = + $位置“+”; –

你必须在url无效字符(即')。 SMS服务器无法正确解析您的SMS消息。使用下面的代码使查询字符串对于GET请求安全/有效。

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

当然,你需要$URL指定值时使用$safeMessage

其他注意事项:

  • 请考虑在网址中删除您从问题敏感的凭据,即真实的用户名和密码。
  • 您的curl请求正在形成POST请求,但GET请求似乎已经足够,因为API可以从url中获取所有信息。