Error when trying to Send SMS via WP_REMOTE POST

i’m facing a little problem here. I have these codes saved in send-sms.php file trying to setup an SMS API using wp_remote_post with my site. As part of my trial every time i run my codes below i get response that i don’t understand.

These are the codes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><?php
require_once 'wp-load.php';
$url = 'https://api.sprintsmsservice.com/api/SendSMS';
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(
'api_id'=>'xxxxxx',
'api_password'=>'xxxxxx',
'sms_type'=>'T',
'encoding'=>'T',
'sender_id'=>'ChonryOTP',
'phonenumber'=>255714812XXX,
'templateid'=>null,
'textmessage'=>'Hello, This is a test message',
),
'cookies' => array()
)
);
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
?>
</code>
<code><?php require_once 'wp-load.php'; $url = 'https://api.sprintsmsservice.com/api/SendSMS'; $response = wp_remote_post( $url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'api_id'=>'xxxxxx', 'api_password'=>'xxxxxx', 'sms_type'=>'T', 'encoding'=>'T', 'sender_id'=>'ChonryOTP', 'phonenumber'=>255714812XXX, 'templateid'=>null, 'textmessage'=>'Hello, This is a test message', ), 'cookies' => array() ) ); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); echo "Something went wrong: $error_message"; } else { echo 'Response:<pre>'; print_r( $response ); echo '</pre>'; } ?> </code>
<?php

require_once 'wp-load.php';


$url = 'https://api.sprintsmsservice.com/api/SendSMS';

$response = wp_remote_post( $url, array(
'method'      => 'POST',
'timeout'     => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking'    => true,
'headers'     => array(),
'body'        => array(
'api_id'=>'xxxxxx',
'api_password'=>'xxxxxx',
'sms_type'=>'T',
'encoding'=>'T',
'sender_id'=>'ChonryOTP',
'phonenumber'=>255714812XXX,
'templateid'=>null,
'textmessage'=>'Hello, This is a test message',

),
'cookies'     => array()
    )
);

if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}


?>

And these are the results when i run the send-sms.php file (You can view full results in this LINK)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> [status_code] => 415
[protocol_version] => 1.1
[success] =>
[redirects] => 0
[url] => https://api.sprintsmsservice.com/api/SendSMS/
[history] => Array
(
)
[cookies] => WpOrgRequestsCookieJar Object
(
[cookies:protected] => Array
(
)
)
)
[filename:protected] =>
)
)
</code>
<code> [status_code] => 415 [protocol_version] => 1.1 [success] => [redirects] => 0 [url] => https://api.sprintsmsservice.com/api/SendSMS/ [history] => Array ( ) [cookies] => WpOrgRequestsCookieJar Object ( [cookies:protected] => Array ( ) ) ) [filename:protected] => ) ) </code>
                    [status_code] => 415
                    [protocol_version] => 1.1
                    [success] => 
                    [redirects] => 0
                    [url] => https://api.sprintsmsservice.com/api/SendSMS/
                    [history] => Array
                        (
                        )

                    [cookies] => WpOrgRequestsCookieJar Object
                        (
                            [cookies:protected] => Array
                                (
                                )

                        )

                )

            [filename:protected] => 
        )

)

Where i’m doing wrong? Because if i reload this file no SMS is sent to my number

2

I have fixed the problem, for future reference you might go through the codes below

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>$api_url = 'https://xxxxxxxx/api/SendSMS/'; // Replace with your API URL
$body = json_encode([
'api_id'=>'xxxxxxxxxxx',
'api_password'=>'xxxxxxxxxxx',
'sms_type'=>'T',
'encoding'=>'T',
'sender_id'=>'xxxxx',
'phonenumber'=>'xxxxxx',
'templateid'=>null,
'textmessage'=>'Robson, This is test message'
//'api_key' => $api_key,
]);
$response = wp_remote_post($api_url, [
'method' => 'POST',
'body' => $body,
'headers' => [
'Content-Type' => 'application/json',
],
]);
// Check for errors
if (is_wp_error($response)) {
error_log('SMS API Error: ' . $response->get_error_message());
return false;
}
// Handle the response
$response_body = wp_remote_retrieve_body($response);
$decoded_response = json_decode($response_body, true);
if (isset($decoded_response['success']) && $decoded_response['success'] === true) {
return true; // SMS sent successfully
}
error_log('SMS API failed with response: ' . $response_body);
return false;
</code>
<code>$api_url = 'https://xxxxxxxx/api/SendSMS/'; // Replace with your API URL $body = json_encode([ 'api_id'=>'xxxxxxxxxxx', 'api_password'=>'xxxxxxxxxxx', 'sms_type'=>'T', 'encoding'=>'T', 'sender_id'=>'xxxxx', 'phonenumber'=>'xxxxxx', 'templateid'=>null, 'textmessage'=>'Robson, This is test message' //'api_key' => $api_key, ]); $response = wp_remote_post($api_url, [ 'method' => 'POST', 'body' => $body, 'headers' => [ 'Content-Type' => 'application/json', ], ]); // Check for errors if (is_wp_error($response)) { error_log('SMS API Error: ' . $response->get_error_message()); return false; } // Handle the response $response_body = wp_remote_retrieve_body($response); $decoded_response = json_decode($response_body, true); if (isset($decoded_response['success']) && $decoded_response['success'] === true) { return true; // SMS sent successfully } error_log('SMS API failed with response: ' . $response_body); return false; </code>
$api_url = 'https://xxxxxxxx/api/SendSMS/'; // Replace with your API URL


$body = json_encode([
    
    'api_id'=>'xxxxxxxxxxx', 
    'api_password'=>'xxxxxxxxxxx', 
    'sms_type'=>'T', 
    'encoding'=>'T', 
    'sender_id'=>'xxxxx', 
    'phonenumber'=>'xxxxxx', 
    'templateid'=>null, 
    'textmessage'=>'Robson, This is test message' 
    
    
    
    //'api_key' => $api_key,
]);

$response = wp_remote_post($api_url, [
    'method'    => 'POST',
    'body'      => $body,
    'headers'   => [
        'Content-Type' => 'application/json',
    ],
]);

// Check for errors
if (is_wp_error($response)) {
    error_log('SMS API Error: ' . $response->get_error_message());
    return false;
}

// Handle the response
$response_body = wp_remote_retrieve_body($response);
$decoded_response = json_decode($response_body, true);

if (isset($decoded_response['success']) && $decoded_response['success'] === true) {
    return true; // SMS sent successfully
}

error_log('SMS API failed with response: ' . $response_body);
return false;

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật