-
Notifications
You must be signed in to change notification settings - Fork 6
/
sms.php
57 lines (44 loc) · 1.7 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
<?php
require 'vendor/autoload.php';
use AfricasTalking\SDK\AfricasTalking;
include('includes/dbconnection.php');
$patient_id = $_GET['patient_id'];
$sql = "SELECT phone FROM patients WHERE id ='$patient_id' ";
$query = mysqli_query($con, $sql);
$row = mysqli_fetch_array($query);
$phoneNumber = $row['phone'];
$randomid = mt_rand(100000,999999);
// Set your app credentials
$username = "hospicare";
$apiKey = "42983a3e1c4dc21db7a7be5552875bf3b0391d88a25c793e914c6cb99ecb188e";
// Initialize the SDK
$AT = new AfricasTalking($username, $apiKey);
// Get the SMS service
$sms = $AT->sms();
// Set the numbers you want to send to in international format
$recipients = $phoneNumber;
// Set your message
$message = $randomid;
// Set your shortCode or senderId
//$from = "Hospicare";
try {
// Thats it, hit send and we'll take care of the rest
$result = $sms->send([
'to' => $recipients,
'message' => 'Here is the access code from Hospicare '.$message.' If this code was requested without you consent, please igonore'
//'from' => $from
]);
print_r($result['status']);
} catch (Exception $e) {
//echo 'fail', $e->getMessage();
}
$query = "SELECT * FROM tblcodes WHERE patient_id = '$patient_id'";
$result = mysqli_query($con,$query);
if(mysqli_num_rows($result) == 0 ){
$sql = "INSERT INTO tblcodes(code, patient_id) VALUES('$randomid','$patient_id')";
}else {
$sql = "UPDATE tblcodes SET code = '$randomid' WHERE patient_id = '$patient_id'";
}
$query = mysqli_query($con, $sql);
echo $randomid;
?>