How Can I Send Sms Using Perl?


If you are using Windows, download and install Strawberry Perl.
After installation, verify by running the following command in the Command Prompt (cmd):


perl -v

If you are using Linux, run the following command in the Terminal to install Perl:


sudo apt update && sudo apt install perl -y perl -v

Before running the script, install the necessary modules using CPAN (Comprehensive Perl Archive Network):


cpan install LWP::UserAgent JSON

If cpan is Not Configured, then Run:


cpan

Then Install modules interactively:


install LWP::UserAgent JSON

Copy and paste this code into a Perl script, save the file as send_sms.pl, and replace its contents with the provided Perl code. Then, update the Authentication_id andAuthentication_key with your credentials. Click Authentication Key ID, and a page will display your 32-character Authentication ID and 32-character Authentication Key, which you can copy and paste into the script.


use strict; use warnings; use LWP::UserAgent; use JSON; my $url = "https://msgpserver.com/api/"; my %data = ( mtype => "N", to => "+91XXXXXXXXXX", message => "This is a test message from Perl...", auth_id => "Authentication_Id", auth_key => "Authentication_Key" ); my $json_data = encode_json(\%data); my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => $url); $req->header('Content-Type' => 'application/json'); $req->content($json_data); my $res = $ua->request($req); if($res->is_success){ print "Response: " . $res->decoded_content . "\n"; } else{ print "Error: " . $res->status_line . "\n"; }

Open a terminal or command prompt and navigate to the file location.
Run the script using:


perl send_sms.pl

Return Success Response.


[ SUCCESS ] {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'success', 'msg': 'success'}

Return Error Response.


[ ERROR ] {'status': 'success', 'login': 'success', 'recharge': 'success', 'host': 'error', 'msg': 'error'} {'status': 'success', 'login': 'success', 'recharge': 'expire', 'host': 'error', 'msg': 'error'} {'status': 'online', 'login': 'error', 'recharge': 'error', 'host': 'error', 'msg': 'error'}


Are you satisfied this Answer?