Email Newsletter Subscriptions via SMS/Text

In a world where your customers are constantly mobile, it’s important to be able to accommodate them by any means possible and as quickly as possible. This means that we’re not always able to send them to an optimized landing page or get them to a specific site, but we can give them another option; text your email and subscribe to a newsletter (or receive specials, codes, etc). This means the customer could simply text “example@fueltravel.com” to your 5 digit short code (or local phone number) and immediately be setup for your campaign/list without ever opening a browser.

Download SMS to Newsletter Script

Before getting into how to actually setup the ability to receive/send SMS messages via Twilio or setting up connections to your email newsletter providers, let’s start with downloading a bit of code to your local machine. To download the most recent version of the script, please visit the following URL either clone the entire repository to your local machine or simply grab the “index.php” file directly.

GitHub Repository: (Direct Download)
git clone https://github.com/revhub/SMS-to-Email-Subscription.git

Once downloaded locally (or onto a remote server), let’s take a look at a few of the items we can customize/tweak to get you up and running as quickly as possible.

Basic Configuration Options:

$enable_mailchimp = "yes";
$enable_exacttarget = "yes";

To keep things simple, the “enable_mailchimp” and “enable_exacttarget” variables allow you to have a “yes” or “no” value to tell the script to run the functions for each service in case you’re only using one or the other (versus both).

$enable_response = "yes";

By default, Twilio will send a SMS response back to the user, but the “enable_response” variable lets you specify whether or not you want to send back a “Thank You” style message (which we can customize in just a moment).


If you’re using MailChimp, please review the following options required for collecting data via the API, otherwise feel free to skip ahead to the ExactTarget options.

First up, you’re going to need to have your personalized API key from MailChimp. To find this information, perform the following steps:

  1. Log into your MailChimp Account, click on your username/name in the top right, and then click on “Account.”
  2. Next, select the “Extras” menu and then the “API Keys” sub-menu in the dropdown.
  3. On this page, you’ll see a section labeled “Your API Keys.” From here, you can either select an existing API key or a create a new one specifically for this script.
  4. Once you have the script, place into the following line of code:

$mailchimp_api_key = "your-example-mailchimp-api-key";

The “mailchimp_login” variable will need to be your actual account access information with your username and password in the following format:

$mailchimp_login = "username:password";

To find your MailChimp “List ID,” you’ll need to perform the following:

  1. Once again, log into your MailChimp account, but this time, select the “Lists” option in the top menu.
  2. On this page, click on your preferred list for subscribing your mobile leads.
  3. Within the list management page, click on “Settings” and then the “List Name & Defaults” option.
  4. Your “List ID” will then appear in the top right corner. Copy and paste this value into the following variable:

$mailchimp_list_id = "your-example-list-id";

As a last step, you’re going to want to grab your data center for your MailChimp account. In order to find this information, log into your account and take a look at the URL of your dashboard which should look something like the following:


In this URL, grab the first subdomain (“us1” in the example) above and paste into the following variable:

$mailchimp_datacenter = "us1";


ExactTarget requires only two variables to get you up and running:

$exacttarget_mid = "";
$exacttarget_list_id = "";

You can obtain your “Member ID” (“mid” for short) in the upper-right hand corner of your ExactTarget/SalesForce Marketing Cloud dashboard under your “account name.” It typically appears as “MID: XXXXXXX” and you’ll need to copy the “XXXXXXX” portion into the “exacttarget_mid” value.

To find your “List ID,” click on your “subscribers” tab to view all of your lists for your account, and then click the checkbox next to the list you want to subscribe leads to upon submission. Once checked, click on the “Properties” button and within this section you should see your “List ID” which you’ll need to paste into your “exacttarget_list_id” variable.


Before discussing signing up or setting up your account, you’ll need to take a look at one variable; “twilio_response.”

If you have the “enable_response” variable set to “yes,” then you can customize the response text in the following variable to send to customers upon a successful submission:

$twilio_response = "Thanks For Subscribing!";

Now, in order to actually start collecting date, you’re going to need to sign up for a Twilio account in order to obtain either a local phone number for your area or to get a 5 digit short code.

The “Free Trial” account allows you access to a single number in your local area code, but you’ll need to add a payment method and validate your account once you’re ready for public numbers to be able to send / receive SMS messages.

Note: Before moving onto the following step, you’ll need to upload your finished script to a publicly accessible server.

With your account setup and personalized number in place, you’re going to want to perform the following:

  1. Log into your Twilio account, then hover over the “Products” menu.
  2. Click on the “Phone Numbers” product link and then select the “Manage” sub-navigation item to view all of your numbers.
  3. Click on your preferred number for this application and then you’ll be able to view all of it’s options and settings.
  4. On this page, scroll down to the “Messaging” section where you should see a “Request URL” input field.
  5. In this field, place the URL to where you’ve uploaded your script and then save your settings.

Upon receiving any texts sent to your selected number within Twilio, the body of the SMS message along with the following fields will all be sent to your script in case you want to store/access more than just the basic information:

  • ToCountry
  • ToState
  • SmsMessageSid
  • NumMedia
  • ToCity
  • FromZip
  • SmsSid
  • FromState
  • SmsStatus
  • Body
  • FromCountry
  • To
  • ToZip
  • NumSegments
  • MessageSid
  • AccountSid
  • From
  • ApiVersion

With this all setup and in place, you’re ready to start collecting leads via something as simple as a text message from your customers. This script is simple, easy to get up and running, and will allow you tons of flexibility to tie into your existing processes (such as SalesForce’s API). We will be writing small updates for new functionality and different email/SMS marketing providers, but should you have any questions with anything, feel free to reach out to us and we’ll be more than happy to help or to just hear how it’s helped you!

Developers Note: Have an idea to improve this script or want to add something new? Feel free to fork within GitHub and we’ll merge into the code for everyone!

Leave a comment below!


Nicholas MercerEmail Newsletter Subscriptions via SMS/Text
Share this post

Related Posts