Send SMS

The Apex\Svc\SmsClient class makes sending SMS messages very simple, and is also part of the Apex Mercry package.

To send a SMS message, first you need to visit the Settings->General menu of your administration panel, and within the API Keys tab enter your Nexmo API key / secret / sender. Please note, using Nexmo is not a requirement and see below for details on changing it. Once API information is entered, here's an example of how to send a SMS message.

<?php

namespace App\MyPackage;

use Apex\Svc\SmsClient;

class MyClass
{

    #[Inject(SmsClient::class)]
    private SmsClient $sms;

    /**
     * Process
     */
    public function process(string $phone):void
    {

        // Send message
        $this->sms->send($phone, "This is an example message");
    }

}

It's that simple. Inject the Apex\Svc\SmsClient class, then call the send() method which only takes two arguments, a phone number and a message. That's it, and the message is sent.

Using Other Providers

By no means is Nexmo a requirement, and it's rather easy to implement your own desired client such as Trello or others. To do so, open the /boot/container.php file and look for the line:

SmsClientInterface::class => \Apex\Mercury\SMS\Nexmo::class

Change that line to any valid class name which supports the SmsClientInterface interface and everything will continue working as expected.