3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SmsGateway { static $baseUrl = "https://smsgateway.me"; function __construct($email,$password) { $this->email = $email; $this->password = $password; } function createContact ($name,$number) { return $this->makeRequest('/api/v3/contacts/create','POST',['name' => $name, 'number' => $number]); } function getContacts ($page=1) { return $this->makeRequest('/api/v3/contacts','GET',['page' => $page]); } function getContact ($id) { return $this->makeRequest('/api/v3/contacts/view/'.$id,'GET'); } function getDevices ($page=1) { return $this->makeRequest('/api/v3/devices','GET',['page' => $page]); } function getDevice ($id) { return $this->makeRequest('/api/v3/devices/view/'.$id,'GET'); } function getMessages($page=1) { return $this->makeRequest('/api/v3/messages','GET',['page' => $page]); } function getMessage($id) { return $this->makeRequest('/api/v3/messages/view/'.$id,'GET'); } function sendMessageToNumber($to, $message, $device, $options=[]) { $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST',$query); } function sendMessageToManyNumbers ($to, $message, $device, $options=[]) { $query = array_merge(['number'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendMessageToContact ($to, $message, $device, $options=[]) { $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendMessageToManyContacts ($to, $message, $device, $options=[]) { $query = array_merge(['contact'=>$to, 'message'=>$message, 'device' => $device], $options); return $this->makeRequest('/api/v3/messages/send','POST', $query); } function sendManyMessages ($data) { $query['data'] = $data; return $this->makeRequest('/api/v3/messages/send','POST', $query); } private function makeRequest ($url, $method, $fields=[]) { $fields['email'] = $this->email; $fields['password'] = $this->password; $url = smsGateway::$baseUrl.$url; $fieldsString = http_build_query($fields); $ch = curl_init(); if($method == 'POST') { curl_setopt($ch,CURLOPT_POST, count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS, $fieldsString); } else { $url .= '?'.$fieldsString; } curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $info = curl_getinfo($ch); $result = curl_exec ($ch); print_r($info['request_header']); $return['response'] = json_decode($result,true); if($return['response'] == false) $return['response'] = $result; $return['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close ($ch); return $return; } } $smsGateway = new SmsGateway('guritsanu.andrei@gmail.com', 'SMSGatewayVoldam'); $deviceID = 27389; $number = '0037379850506'; $message = 'Hello World!'; //Please note options is no required and can be left out $result = $smsGateway->sendMessageToNumber($number, $message, $deviceID); ?>
Output for 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
Deprecated: Creation of dynamic property SmsGateway::$email is deprecated in /in/smio2 on line 5 Deprecated: Creation of dynamic property SmsGateway::$password is deprecated in /in/smio2 on line 6 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/smio2:58 Stack trace: #0 /in/smio2(35): SmsGateway->makeRequest('https://smsgate...', 'POST', Array) #1 /in/smio2(89): SmsGateway->sendMessageToNumber('0037379850506', 'Hello World!', 27389) #2 {main} thrown in /in/smio2 on line 58
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/smio2:58 Stack trace: #0 /in/smio2(35): SmsGateway->makeRequest('https://smsgate...', 'POST', Array) #1 /in/smio2(89): SmsGateway->sendMessageToNumber('0037379850506', 'Hello World!', 27389) #2 {main} thrown in /in/smio2 on line 58
Process exited with code 255.
Output for 5.6.0 - 5.6.25
Fatal error: Call to undefined function curl_init() in /in/smio2 on line 58
Process exited with code 255.

preferences:
74.84 ms | 409 KiB | 5 Q