[英]Sending Sms From PHP Script
我正在使用PHP脚本通过我的sms api发送消息。 短信发送成功,但我的信息出现问题。 仅剩余“ 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);
?>
网址中包含无效字符(即'
)。 SMS服务器无法正确解析您的SMS消息。 使用下面的代码可以使查询字符串对GET请求安全/有效。
$message1 = "..."; // Your original message
$safeMessage = urlencode($message1);
当然,向$URL
分配值时需要使用$safeMessage
。
补充笔记:
我假设您已经使用上述设置从msg91获得了短信服务,或者您可以使用Twilio,Nexmo等任何短信服务提供商。现在,我正在创建一个通用函数,您可以在PHP代码中的任意位置调用该函数以发送任何类型的短信。
//send otp message
public static function sendMessage($mobile, $message)
{
$message = urlencode($message);
$url = sprintf("http://api.msg91.com/api/v2/sendsms?authkey=%s&mobiles=%s&message=%s&sender=%s&route=%s",
env('MSG91_AUTH_KEY'), $mobile, $message, env('MSG91_SENDER_ID'), env('MSG91_ROUTE'));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
有关更多详细信息: https : //www.lelocode.com/posts/sending-sms-like-otp,-welcome-message,mobile-verification-using-php---lelocode
http POST API用于发送短信。 这里使用simplexml_load_file()函数执行该过程。
$to="88".$this->mobile_no; //Country code concatenation $gsm =$to; // Formed as ISD number $msg ="Thank you"; //SMS content that will be sent $user = 'úsername'; // API username $password = 'password'; //API password $sender =sender; // i.e.: 880155911456 or Sender id might be alfanumeric for masking $url = "http://api.olineit.com/api/v3/sendsms/plain?user=$user&password=$password&sender=$sender&SMSText=$msg&GSM=$gsm&"; //http REST API url $smsResult = simplexml_load_file($url); // Function called and parameter passed.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.