How to Send an Email Using SMS

January 13, 2024
Written by
SendGrid Team
Opinions expressed by Twilio contributors are their own

How to Send an Email Using SMS

Sending an email with text might seem old school (or new school?), but it's a powerful way to send email communications when you don't have internet access. 

In a world of online communication, it’s easy to forget that channels like SMS don’t need an internet connection to function. Because 3.5 billion people around the world utilize smartphones, online communications can feel like the default. However, there are millions of feature phones still in use around the world. India alone accounts for 400 million of these feature phones. 

Imagine for a moment that you need to send an email without internet access. What do you do—where do you start? 

Email doesn't exist solely online. Offline sending is a great alternative that enables senders to have flexible sending practices and provides them the space to be creative with their communications.

What if you could send an email using SMS? In this tutorial, we’re going to coach you on how to send an email using Twilio SMS in PHP with Twilio SendGrid. But first—let's cover some high-level topics.

Benefits and limitations of using text for email communication

In the realm of digital communication, merging SMS with email offers a unique blend of accessibility and convenience. However, like any technology, it comes with its own set of advantages and challenges.

Benefits of sending email with text

  1. Accessibility: SMS-to-email bridges the gap between feature phones and smart devices, making it an invaluable tool in areas with limited internet connectivity. It extends the reach of email to virtually anyone with a mobile phone.

  2. Cost-effective: For users in regions with expensive or limited internet access, SMS offers a more affordable way to send emails. It’s especially beneficial for businesses looking to communicate with customers in such areas.

  3. Speed and convenience: SMS is known for its immediacy. Integrating SMS with email allows for quick sending of emails without the need for a data connection, which is particularly useful in urgent or time-sensitive situations.

  4. Simplicity: The process doesn’t require high-tech skills. Anyone familiar with sending a standard text message can easily adapt to sending emails via SMS, making it user-friendly for a broad audience.

Limitations of sending email with text

  1. Formatting constraints: SMS lacks the rich formatting capabilities of typical email services. Emails sent via SMS will be plain text, without the ability to include elements like bold or italic text, images, or attachments.

  2. Character limit: SMS restricts the number of characters per message. This limitation can be challenging when trying to send longer emails, potentially requiring the sender to split the content across multiple messages.
  3. Dependency on cellular network: While not requiring the internet, this method is reliant on a stable cellular network. In areas with poor mobile reception, sending emails via SMS might be inconsistent or delayed.

  4. Potential security concerns: Sending sensitive information via SMS may pose security risks, as standard text messaging lacks the encryption of most email services. It’s important to consider the type of information being transmitted.

  5. Cost considerations: While sending an SMS can be cost-effective for the sender, it’s important to consider that receiving and responding to these messages might incur costs for the recipients, depending on their mobile plan.

What you’ll need to send email with text

To send email using text, your computer will need to be set up with the following tools and packages:

Prepare your development environment

Start by creating a folder in your computer where you will keep all of the necessary files to start sending emails using SMS. For this tutorial, we’ll call the folder sms_email.

After creating this folder, create the following empty files inside of it:

      1. .env
      2. functions.php
      3. webhook.php

Run the command below to complete all actions simultaneously:

NOTE: The .env file is a hidden file used to store secret or private keys on your server.  Because it is not accessible from the browser, API keys and credentials can be safely stored inside and accessed from anywhere within the app on the server-side.

Install the necessary packages

To enable the support of the .env file, you’ll need to install the PHP dotenv package using Composer. Run the following command in your terminal inside of the project directory:

Now, you’ll need to install the Twilio PHP SDK in order to connect your project to Twilio’s APIs. Run the following command in your terminal:

Set up your Twilio phone number and credentials

If you haven’t already done so, please take a moment to create a new phone number on your Twilio account. To send and receive SMS from your project, you’ll need to collect the following information from the Twilio Console:
      • Twilio Account SID
      • Twilio Auth Token
      • A phone number in E. 164 format
Once you have located these items, add them to your .env file.

Set up your Twilio SendGrid credentials

By using Twilio SendGrid, a cloud-based SMTP provider, you can send email without having to maintain your own email servers.

All you’ll need to enable sending email within your app is the SendGrid PHP package and a SendGrid API key.

Once you have your key, update the .env as follows:

Next, install SendGrid’s PHP package by running the following command in your terminal:

Create your email sending helper function

Now we’re going to create a simple helper function that accepts a few parameters, processes them, and then sends messages to the recipient using SendGrid.

Below is a simple email sending function using SendGrid. Add the following code to the functions.php file:

NOTE: The FROM_EMAIL and FROM_NAME variables will need to be added to your .env file using your respective values.

Establish a Twilio webhook

When text messages are sent to your Twilio designated number, Twilio sends a response containing information about your SMS back to the application using a Twilio webhook.

You will need to create your own webhook to receive and process the email sending requests. In the webhook.php file, copy and paste the following code into it.

Congratulations! You’re only a few steps away from sending email using SMS.

Assign the webhook URL

After setting up the webhook.php function, you’ll need to assign a URL to the phone number on your Twilio settings page. Now, every time you send an SMS to your Twilio designated-number, Twilio will send data to this URL and your functions.php for processing.

For this tutorial, we’re working from our local system and there’s no way to route our local URL to Twilio because the local dev environment is not connected to the internet. This is where ngrok comes in, allowing the application to be accessed online.

If you don’t have ngrok set up on your computer, their official download page has detailed instructions on how to do so.

For our app, we’re going to run our PHP application using its built-in server. From the terminal, run the following command to start the server:

In a new terminal window, start ngrok by assigning it to the same port as the active PHP server:

Your terminal window should look like this:

Terminal window displaying ngrok assigned to the active PHP server

Your Twilio project will use Forwarding URL provided above, followed by the path to the webhook file. For example, ours is:

The final step is connecting your Twilio number to the webhook we created. Navigate to the active numbers on your dashboard and click on the number you would like to use. In the Messaging section, find the input labeled “A MESSAGE COMES IN.” Replace the URL with your webhook URL and click “Save.”

Twilio dashboard displaying connection between webhook URL and Twilio phone number

Test your app

Send an SMS with the following format to your Twilio number:’m sending this email using Twilio SMS

Great job! You can now send emails using SMS. When you’re ready for a new challenge, this project can be expanded to make the SMS seem more interactive (similar to a chatbot) as well as allowing sending to multiple addresses.

Regardless of whether you send online or offline, SMS and email are forces to be reckoned with in your communications strategy. Combining these forces can maximize your capacity to reach customers wherever they are, on the platform that they prefer. For a comprehensive guide on all things email and SMS, check out Using SMS and Email to Engage Your Customers in 2020

Recommended For You

Most Popular

Send With Confidence

Partner with the email service trusted by developers and marketers for time-savings, scalability, and delivery expertise.