Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gaan10's avatar

Not able to use curl->post to send sms foreach mobile numbers.

I need to send sms to mobile nos. and while doing that i iterate over an array and send .But when i use curl->post i am not able to iterate .It sends only one time.what can be the issue.

foreach($new_tokens as $new_tokenss)

      {
    
       foreach($new_tokenss as $new_token)
    
            {
        
$message = "Message";
        $message_encoded = urlencode($message);
        $postData = array(
            'authkey' => \Config::get('procedures.msg91.authKey'),
            'mobiles' => $new_token->mob,
            'message' => $message_encoded,
            'sender' => \Config::get('procedures.msg91.senderId'),
            'route' => \Config::get('procedures.msg91.route')
        );
      
        $curl = new \anlutro\cURL\cURL;
        $curl->post(\Config::get('procedures.msg91.api_url'), $postData);
        
    }
          
        }
0 likes
6 replies
Snapey's avatar

Because you have your return statement inside the foreach loop. It runs once and then exits from your function.

gaan10's avatar

even if i remove return then also same. problem is with the curl post.any pointers on what is the issue there

Snapey's avatar

Well, your code was broken before, but you could not see it. What else is wrong?

Without knowing if new_token contains valid (and different) data then how can we tell?

$new_tokenss might only have one new_token for instance.

gaan10's avatar

@Cronix sorry bud because the issue was with curl and post . If i remove curl and post it iterates good.

Please or to participate in this conversation.