Wordpress SMS API integration without plugin

I am struggling with SMS sending in WordPress without plugin, I have a, API, but that API is not working. Example:

function mysite_woocommerce_order_status_processing( $order_id ) {

    $mobile="123456";

    $url="****/api.php?username=******password=1234source=UPDATEdmobile=".$mobile."message='.$msg.' ";

    $response = wp_remote_get( $url );

    //print_r($response);

}

add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

I am struggling with above hook, I can send Email through that hook, but not SMS. It would be great if any WordPress developer help me out !

Getting SyntaxError:

JSON.parse: unexpected character at line 1 column 1 of the JSON data

Topic sms api Wordpress

Category Web


function mysite_woocommerce_order_status_processing( $order_id ) {

  $mobile="123456";

  $url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='.$msg.' ";

  $response = file_get_contents( $url );

  //print_r($response);

   }

   add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

use file_get_contents( $url ) instead of wp_remote_get($url) it will work fine


I think this is the error. The last variable $msg is incorrectly inserted. Here is the corrected code.

function mysite_woocommerce_order_status_processing( $order_id ) {

    $mobile="123456";

    $url="****/api.php?username=******&password=1234&source=UPDATE&dmobile=".$mobile."&message='".$msg."'";

    $response = wp_remote_get( $url );

    //print_r($response);

}

add_action( 'woocommerce_order_status_processing','mysite_woocommerce_order_status_processing' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.