-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsms.php
70 lines (45 loc) · 1.59 KB
/
sms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
//url encode *
//#->%23
//*->%2A
include('connect.php');
include('AfricasTalkingGateway.php');
$phoneNo = $_REQUEST['phoneNo'];
$message = $_REQUEST['message'];
registerUser($phoneNo,$message);
function registerUser($phoneNo,$message){
$exploded = explode("*", $message);
$full_name = $exploded[0];
$national_id = $exploded[1];
//check if the user exists
$query = mysql_query("SELECT phone_number FROM users WHERE phone_number='$phoneNo'");
if(mysql_num_rows($query) > 0){
echo $msg="You are already registered your account is active.";
}else{
//create the user
$result = mysql_query("INSERT INTO users (phone_number,full_name,national_id) VALUES ('$phoneNo','$full_name','$national_id')");
echo $msg= "You have successfully registered to this service";
sendSMS($phoneNo,$msg);
exit;
}
}
//SEND SMS FUNCTION USING AFRICA'S TALKING API
function sendSMS($recipients,$msg){
//require_once('AfricasTalkingGateway.php');
$username = "stevebab";
$apikey = "c8933dc169561310819188ca7d69db1a7a967a05bd3c952bad081ea3f71a5ce8";
//$recipients = "0723401197";
$message = $msg;
// Create a new instance of our awesome gateway class
$gateway = new AfricasTalkingGateway($username, $apikey);
try{
// Thats it, hit send and we'll take care of the rest.
$results = $gateway->sendMessage($recipients, $message,$from);
foreach($results as $result) {
}
}
catch ( AfricasTalkingGatewayException $e )
{
echo "Encountered an error while sending: ".$e->getMessage();
}
}