Whether we’re voting for our favorite candidate on shows such as X Factor, or receiving two-factor authentication codes to log in to services like MailChimp and GitLab, SMS are virtually ubiquitous in modern life. Not only do they make communication in life and work much easier, it also doesn’t take a lot of code to send them either.

In this tutorial, you’ll learn how to create a simplistic API that can send an SMS using PHP’s  Mezzio framework and  Twilio’s PHP SDK.

Once completed, you will be able to send a POST request to the API’s default endpoint, supplying the phone number to send the message to, and the message to send. If the message was successfully sent, then a JSON response will be returned showing a number of details about the sent SMS. If the SMS was not able to be sent, then an appropriate JSON response will be returned, which will show what went wrong.

Overall, this tutorial will provide you with a basic understanding of creating endpoints in Mezzio and sending SMS with Twilio.

Prerequisites

In order to complete this tutorial, you will need the following:

  • PHP 7.4
  • Composer globally installed
  • Twilio account and phone number
  • twilio-cli
  • curl
  • jq
  • libsecret
  • Node.js 10.12.0 or higher

#php #mezzio #php framework

How to Send an SMS with Mezzio PHP Framework
4.55 GEEK