Search code examples
phplaravelvonage

Nexmo sms laravel not working


Basically there is a faulty reading which triggers an event called 'AbnormalReadingWasTaken' which I've registered two listeners under 'AbnormalReadingWasTaken' in my 'EventServiceProviders' where the first listener 'AddReadingsToAlertsTable' works fine however the other listener 'SendAlertSMS' doesn't seem to work. What am I missing, can anyone help me with this? I believe this has something to do with the curl script of the nexmo sms?

<?php

namespace App\Listeners;

use App\Events\AbnormalReadingWasTaken;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendAlertSMS
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  AbnormalReadingWasTaken  $event
     * @return void
     */
    public function handle(AbnormalReadingWasTaken $event)
    {
        $url = 'https://rest.nexmo.com/sms/json?' . http_build_query([
        'api_key' => 'xxxxx',
        'api_secret' => 'xxxxx',
        'to' => 'xxxxx',
        'from' => 'xxxxxx',
        'text' => 'Hello from Nexmo'
        ]);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    }
} 

Solution

  • Sorry for the trouble caused, nothing wrong with the code, the error was because of the wrong api_key, my mistake cant believe I actually copied the wrong api_key. -_-