简体   繁体   中英

How to send a SMS through PHP form?

I have one simple PHP form for sending SMS, I'm trying to send a SMS to one number but it gives me a success message "SMS has sent..." along with the error "Invalid Username/Password".

I manually check the link by putting it in browser it works fine, I have got SMS by this process....

Please help me to solve this!!!

<?php
if(isset($_POST['submit']))
{

$number=$_POST['numbertext'].$_POST['number'];
$message=$_POST['message'];


$var="http://sms.************.com/*****.asp?user=username&password=
password&sender=sender&sendercdma=**********&text=".$message."&PhoneNumber=".$number."&track=1";

    echo $var;

    $curl=curl_init('http://sms.************.com/*****.asp');
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $var);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $result= curl_exec($curl);
    echo $result;
    curl_close($curl);
    die("SMS has sent.....");

    }

?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<form method="post">
Number:<br/>
<input type="text" name="numbertext" />-<input type="text" name="number" />
<br/><br/>

<br/><br/>
Message:<br/>
<textarea name="message"></textarea>

<input type="submit" name="submit" value="Send"/>
</form>
</body>
</html>

Sent SMS Through msg91 API,I am still not clear with your API inputs.

$YourAuthKey="Your Key";
$mobiles="number";
$message="Transactional Message";
$country=91;
$senderid="XYZMSG";
$url="https://control.msg91.com/api/sendhttp.php?authkey=".$YourAuthKey."&mobiles=".$mobiles."&message=".$message."&sender=".$senderid."&route=4&country=91";
echo $url;
header("Location: $url");

By checking their api, you should do as follow :

$postData = array(
    'authkey' => $authKey,
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

//API URL
$url="https://control.msg91.com/api/sendhttp.php";

// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
));

And definitely not pass your url as follows :

curl_setopt($curl, CURLOPT_POSTFIELDS, $var);
$YourAuthKey="authkey";
$mobiles="mobile";
$message="demo";
$country=91;
$senderid="625552";// your sender id should be 6 digit
$url="http://********/api/*****.php?authkey=$YourAuthKey&mobiles=$mobiles&message=$message&sender=$senderid&route=4&country=$country";

// echo $url;

$curl=curl_init('http://*******/api/*****.php');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $var);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec($curl);
echo $result;
curl_close($curl);
die("SMS has sent.....");

You can send SMS using mvayoo api easily first create Account on www.mvaayoo.com. Then u will get your username, password detail. Fill this detail in following code and send SMS easily

<?php$ch = curl_init();
 $user="enter your account email id here:enter your password here";
 $receipientno="enter recivermobile number here";
 $senderID="TEST SMS";
 $msgtxt="this is test message, test";
 curl_setopt($ch,CURLOPT_URL, "http://api.mVaayoo.com/mvaayooapi/MessageCompose");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS,"user=$user&senderID=$senderID&receipientno=$receipientno&msgtxt=$msgtxt");
 $buffer = curl_exec($ch);
 if(empty ($buffer)){
   echo " buffer is empty ";
 }else{
   echo $buffer;
 }
 curl_close($ch);
>

www.gajabwap.blogspot.in

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