Search code examples
apilaravel-4sendvonage

how to send text to US numbers in Nexmo


Sending message to Philippines is simple as pie.

But in US numbers, I'll have to go through verification that I do not know how.

I started 2F Authentication but seems that I dont know how to do next.

My question: How to add send text to US numbers in Nexmo?


Solution

  • You can use Nexmo's SMS API which allows you to send a text in over 200 countries with a simple HTTP call.

    You can sign up for a virtual number which allows you to send SMS messages & receive incoming message as well.

    For 2FA, you can use the Verify API to authenticate users to a specific device.

    This method is more secure than using an SMS API and randomly generating numbers yourself. The pin will then entered by the end user & checked by the Verify API.

    It takes a few lines of code to use either of these APIs. Below is a block of code in PHP which allows you to send a text using the SMS API.

    <?php
    $url = 'https://rest.nexmo.com/sms/json?' . http_build_query([
    'api_key' => API_KEY,
        'api_secret' => API_SECRET,
        'to' => YOUR_NUMBER,
        'from' => NEXMO_NUMBER,
        'text' => 'Hello from Nexmo'
    ]);
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    

    Here is the documentation for Nexmo's SMS API for reference.

    Here is the documentation for Nexmo's Verify API if you were looking for a simple 2FA solution.