in reply to Re^3: joining string content
in thread joining string content

This is wat i tried, but not working because the receipts numbers have to be this way

my @recipients = ("+1234567890", "+1234567890");
my $sender = $CGI->param("sender"); my $phone = $CGI->param("phonenumber"); # so am entering this way +1 +2344, +123344, +45454444 in textarea my $message = $CGI->param("message"); my $rep = ''; if ($sender) { my @raw_params = split /\s+/, $phone; my @quoted_params = map { qq{"$_"} } @raw_params; my $quoted_params_string = join ", ", @quoted_params; my @recipients = ($quoted_params_string); foreach my $recipient (@recipients) { my $req = HTTP::Request->new(POST => 'https://api.twilio.com/2010-04-0 +1/Accounts/AC5b68......756/Messages.json'); $req->content_type('application/x-www-form-urlencoded'); $req->authorization_basic("AC5b686.....56", "cd3.......d"); $req->content("To=$recipient&From=$sender&Body=$message"); my $response = $ua->request($req); if ($response->is_success) { $rep = "<p style='color: #29AB87;'>Messages Sent</p>"; } else { $rep = "<p style='color: #BF4F51;'>Nothing Sent</p>"; } } }

Replies are listed 'Best First'.
Re^5: joining string content
by Corion (Patriarch) on Jun 24, 2025 at 13:10 UTC

    From my cursory reading of the Twilio documentation of the Message API, it expects $message to contain a JSON message as in the examples.

    You send some string in the Body parameter that may or may not be a properly URL-encoded JSON message that Twilio expects.

    Also, concatenating strings does not make something x-www-form-urlencoded. You should properly URL-encode the parameters or look (for example) at the URL::Encode module for properly encoding all the parameters. Especially, your phone numbers contain the + character, which needs to be URL-encoded, for example as %22.

      i have no any problem with script, am sending sms very well, but when i try to send bulk by entering numbers in this way +1234, +23444 in html. it doesn't work.

      i can only send bulk by doing this in backend like this my @recipients = ("+233434", "+233434");

      i didnt say there is any problem of sending, only problem is receipts

Re^5: joining string content
by tybalt89 (Monsignor) on Jun 24, 2025 at 15:09 UTC

    replace

    my @raw_params = split /\s+/, $phone; my @quoted_params = map { qq{"$_"} } @raw_params; my $quoted_params_string = join ", ", @quoted_params; my @recipients = ($quoted_params_string);

    with

    my @recipients = $phone =~ /[+\d]+/g;

      wow it worked, thanks so much so so so much