-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsms.php
More file actions
63 lines (50 loc) · 1.78 KB
/
sms.php
File metadata and controls
63 lines (50 loc) · 1.78 KB
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
<?php
/*
curl -X POST https://rest.nexmo.com/sms/json \
-d api_key=eeb3aeb3 \
-d api_secret=3J33DCz1AQevWPsU \
-d to=66817264466 \
-d from="NEXMO" \
-d text="Hello from Nexmo"
*/
class sms {
private $conn = null;
private $endpoint='rest.nexmo.com';
private $uri='sms/json';
private $port = '443';
private $api_key='eeb3aeb3';
private $api_secret='3J33DCz1AQevWPsU';
private $from='ega';
private function __construct(){ }
public static function init(){
$instance = new self();
return $instance;
}
public function sendSMS($to, $msg, $SSL=true){
if( is_null($this->conn) ){
$this->conn = curl_init();
}
if( !is_null($this->conn) ){
if( $SSL == true){
curl_setopt($this->conn, CURLOPT_URL, "https://$this->endpoint:$this->port/$this->uri");
}else{
curl_setopt($this->conn, CURLOPT_URL, "http://$this->endpoint:$this->port/$this->uri");
}
$playload = "api_key=".$this->api_key."&api_secret=".$this->api_secret."&to=".$to."&from=".$this->from."&text=".$msg;
curl_setopt($this->conn, CURLOPT_POSTFIELDS, $playload);
curl_setopt($this->conn, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->conn, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($this->conn);
if ($response === false) {
$info = curl_getinfo($this->conn);
curl_close($this->conn);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($this->conn);
return $response;
}else{
return "Oops! Something weng wrong";
}
}
}
?>