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

insight's avatar

How to resolve the cURL error in Laravel 10 SMS sending ?

Dear Friends, My code works fine , but today when I look I can see my SMS sending functionality in ajax is not working. my error screenshot is Error screenshot

I am using Red hat linux server with Apache.

Please advise

Thanks

Anes P A

0 likes
10 replies
Snapey's avatar

wow, you really have over 700 lines of code in your ApplicantController?

Whatever you did on line 722, failed, and you appear not to catch the exception, letting it bubble through to your ajax request

Since you don't show anything about how you send SMS, noone can help

insight's avatar

@Snapey My Controller SendOTP functionality is

public function SendOTP(Request $request)
{   
    $mobile = $request->input('mobile_no');

    // Check if an OTP request has been made for this mobile number in the last 20 seconds
    if (!Cache::has('otp_request_' . $mobile)) {
        $pin = mt_rand(100000, 999999);
        $message1 = "KSRTC - " . $pin . " is your OTP for application submission confirmation. Please enter it to proceed.";
        $str = 'username=ksrtcfrontoffic&password=ksrtc123499&message=' . $message1 . "&numbers=" . $mobile . "&senderid=KSRTCMG";
        $url = 'http://api.sms.tn.gov.in/fastclient/SMSclient.php?' . $str;
        session(['otp' => $pin]);
        $response = Http::get($url);

        if ($response->ok()) {
            // Set a rate limit for this mobile number for 20 seconds
            Cache::put('otp_request_' . $mobile, true, 20);

            return response()->json(['success' => true]);
        }
    }

    return response()->json(['success' => false]);
}

Please help

Snapey's avatar

So many bad practices

WAIT, you allow the user to specify the mobile number to use? That totally breaks the point of OTP. I thought you had this app security checked?

  1. If you just published your service credentials in this post, edit the question, and request a new password from the provider
  2. put something like this in its own class
  3. extract username, password and url into a service config which gets its values from ENV. Don't bake them into your code. At present If any of the values change you have to redeploy your code. Also, you dont want service credentials stored in your code repo.
  4. catch exceptions thrown by the Http request

The error is that the connection timed out.

Either the url changed, or your credentials are not valid or the service is down

1 like
insight's avatar

@Snapey and all : That credentials and details are dummy values ( for posting here). My Question is this SMS service and form is working in localhost as shown Localhost working screenshot

It's shown that error in Staging Server . What may be I am wrong ?

Please advise

insight's avatar

Dear Team, At last I found error reason. There is no active internet connection in staging server. cURL is not working for SMS gateway as

[root@KSRTCApp ~]# curl -I http://api.sms.tn.gov.in
curl: (28) Failed to connect to api.sms.tn.gov.in port 80: Connection timed out

Am I right friends ?

Please advise

Thanks

Anes P A

Snapey's avatar

@insight not sure I should bother answering as you clearly know better than to take my advice

If the staging server has no connection to the internet, how did you install the app?

Of you dont have command line access to the server then this must be a toy hobby project, yes?

insight's avatar

No it's a staging server. I can access server through my network but if server is away from internet it cannot access a resource like sms gateway. Hope you get me ?

Snapey's avatar

@insight how did you install the application on the server (ie, composer install etc)

You get me, or perhaps language is a barrier?

insight's avatar

@Snapey No barrier sir, all installations are over in server. On that time internet availability is there.

Snapey's avatar

@insight well obviously, the machine is going to need internet access if it wants to communicate with the outside world. I would have thought that obvious???

1 like

Please or to participate in this conversation.