45 lines
1.5 KiB
PHP
45 lines
1.5 KiB
PHP
<?php
|
|
class SmsService {
|
|
public static function sendSms($to, $message) {
|
|
$sms_config = require __DIR__ . '/../config/sms.php';
|
|
$api_key = $sms_config['smslink']['api_key'];
|
|
$sender = $sms_config['smslink']['sender'];
|
|
|
|
if ($api_key === 'YOUR_SMSLINK_API_KEY') {
|
|
// Don't send SMS if the API key is not set
|
|
error_log('SMS not sent: SMSLink API key is not set.');
|
|
return ['success' => false, 'error' => 'SMSLink API key is not set.'];
|
|
}
|
|
|
|
$url = 'https://secure.smslink.ro/sms/gateway/communicate/index.php';
|
|
$post_fields = [
|
|
'connection_id' => $api_key,
|
|
'to' => $to,
|
|
'message' => $message,
|
|
'sender' => $sender,
|
|
];
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_fields));
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$response = curl_exec($ch);
|
|
$err = curl_error($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
if ($err) {
|
|
return ['success' => false, 'error' => $err];
|
|
} else {
|
|
// Basic check for success response from SMSLink
|
|
if (strpos($response, 'RESPONSE_CODE: 0') !== false) {
|
|
return ['success' => true];
|
|
} else {
|
|
return ['success' => false, 'error' => $response];
|
|
}
|
|
}
|
|
}
|
|
}
|