Drop us a line
info@asenass.com
support@asenass.com
Visit our office
Nairobi Office, Kenya
$username,
'to' => $recipient,
'message' => $sms_message
]);
$headers = [
"apiKey: $apiKey",
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$curl_error = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$responseData = json_decode($response, true);
if ($curl_error) {
$error_message = 'Failed to send SMS: ' . $curl_error;
} elseif ($http_code == 401) {
$error_message = 'Failed to send SMS: Unauthorized (HTTP 401). Check API key and username.';
} elseif ($http_code == 400 && isset($responseData['SMSMessageData']['Message']) && strpos($responseData['SMSMessageData']['Message'], 'Low balance') !== false) {
$error_message = 'Failed to send SMS: Insufficient account balance.';
} elseif ($http_code !== 201 && $http_code !== 200) {
$error_message = 'Failed to send SMS. HTTP code: ' . $http_code;
} elseif (isset($responseData['SMSMessageData']['Recipients']) && count($responseData['SMSMessageData']['Recipients']) > 0) {
$allSuccessful = true;
foreach ($responseData['SMSMessageData']['Recipients'] as $recipientData) {
if ($recipientData['status'] !== 'Success') {
$allSuccessful = false;
if ($recipientData['status'] === 'UserInBlacklist') {
// Fallback to email
try {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'asenassdevelopers@gmail.com';
$mail->Password = 'vcbaienlaiavdwas';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('asenassdevelopers@gmail.com', 'Quote Request');
$mail->addAddress($to_email);
$mail->isHTML(true);
$mail->Subject = 'New Quote Request: ' . $subject;
$mail->Body = "
New Quote Request
Name: " . htmlspecialchars($name) . "
Email: " . htmlspecialchars($email) . "
Subject: " . htmlspecialchars($subject) . "
Message: " . htmlspecialchars($message) . "
"; $mail->AltBody = "New Quote Request\nName: $name\nEmail: $email\nSubject: $subject\nMessage: $message"; $mail->send(); $success_message = 'Your request has been sent successfully via email!'; } catch (Exception $e) { $error_message = 'Failed to send email: ' . $mail->ErrorInfo; } } else { $error_message = 'SMS not delivered: ' . $recipientData['status']; } } } if ($allSuccessful) { // Send email as well try { $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; $mail->SMTPAuth = true; $mail->Username = 'asenassdevelopers@gmail.com'; $mail->Password = 'vcbaienlaiavdwas'; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; $mail->setFrom('asenassdevelopers@gmail.com', 'Quote Request'); $mail->addAddress($to_email); $mail->isHTML(true); $mail->Subject = 'New Quote Request: ' . $subject; $mail->Body = "New Quote Request
Name: " . htmlspecialchars($name) . "
Email: " . htmlspecialchars($email) . "
Subject: " . htmlspecialchars($subject) . "
Message: " . htmlspecialchars($message) . "
"; $mail->AltBody = "New Quote Request\nName: $name\nEmail: $email\nSubject: $subject\nMessage: $message"; $mail->send(); $success_message = 'Your request has been sent successfully via SMS and email!'; } catch (Exception $e) { $error_message = 'SMS sent, but failed to send email: ' . $mail->ErrorInfo; } } } else { $error_message = 'Failed to send SMS: No recipients processed.'; } } ?>
Request a quote