Zen Cart custom software development, Zen Cart modules, Zen Cart Expert eCommerce with Zen Cart!

Zen Cart SMS on sale

Zen Cart SMS On Sale

A Zen Cart™ mod which allows you to send yourself a text message when a sale is made.

Donate: This is free software. Show your appreciation by supporting my efforts. Donate

Relevance: Zen Cart™ 1.3.6 - 1.3.9, 1.5.x

Current Version: 1.1a (version history)

Support Thread: SMS On Sale Support Thread

Cost: Free, but donation appreciated

Installation Instructions: click here

Location: Zen Cart Plugins, under Admin Tools

Download: SMS On Sale in Zen Cart Plugins

FAQ: click here


When you get an order, this mod will send a brief email to your email-to-SMS gateway, which will be turned into a text message to your mobile device (cell phone). The text will contain the name of the person who sent the order and the amount of the order.

You must have an SMS-capable mobile device and an email-to-SMS-gateway to use this mod. Most North American carriers offer email-to-SMS as a free feature. If you live outside North America or do not have an email-to-SMS gateway as part of your mobile service contract, you may use a Commercial email-to-SMS gateway, or you may use a service like I Want Sandy, as described below. (The text below describes using Sandy as a reminder service; to get an immediate SMS from Sandy, change the $prefix string.)

If messages sent to your mobile's email address are not converted to SMS messages (but rather delivered to a mobile email client), you will need to figure out how to convert inbound emails to SMS messages, and make the necessary adjustments to this mod. Ask your service provider (not me!).

Alternate SMS services - I Want Sandy

Note: The company behind I Want Sandy is closing its doors December 8, 2008. For the time being, I Want Sandy will be offline. You should use Twitter or another alternative instead. I Want Sandy! In addition to getting an immediate text message when a sale occurs, you can use this mod in conjunction with the service I Want Sandy, which will email you (and/or SMS you) with a follow up reminder after a period of time you specify. As an example, suppose you want a reminder to follow up by phone on all overs over $250 in one week. This is what you would add to class.msg_owner.php right after the call to zen_mail:

       if ($order->info['total'] > 250) {
          $oid = $_SESSION['order_number_created'];
          $sandy_email = "xxxxx@youraccount.iwantsandy.com";
          $prefix = "Remind me in 5 days to follow up with this customer\n";
          $customer_info = $order->customer['firstname'] . " " .  $order->customer['lastname'] . "\n" . 
             "Order Number " . $oid . "\n" . 
             $order->customer['telephone'] . "\n";
          $email_text = $prefix . $customer_info;
          zen_mail('Sandy', $sandy_email, 'Order Followup', $email_text, 
             STORE_NAME, EMAIL_FROM, $empty_block, "msg_owner",'');

In five days you would get an email and a text message with information something like this:

Follow up with this customer Scott Wilson Order Number 25 813-555-1212

Of course, you would fill in $sandy_email with your actual personal Sandy email address. And obviously, you must set up an account with Sandy and fully configure it for this to work. In particular, you must set up your store's email address as a secondary email address for Sandy if it is not the primary email address.

Zen Cart operators outside of North America who do not have a free email to SMS gateway may want to use I Want Sandy as their primary notification mechanism. In this case, the message would be just "Remind me to follow up ..." (i.e. delete the "in 5 days").

Alternate SMS services - Twitter

Twitter Zen Cart operators outside of North America who do not have a free email to SMS gateway may want to use Twitter as their primary notification mechanism. I assume you already have a personal Twitter account (if you don't, create one). You should first create a special Twitter account for your store, and ensure that it is able to SMS message your country code. You will also want to modify your settings on this account so that your updates are protected. Then on your personal Twitter account, do a "follow" of your business account. Since updates are protected, this sends a request to your business account that you will need to approve. Approve it from your business account, and do a test tweet from your business account. This should show up on your personal account. On your personal account, click the name of your business account and turn device updates on (you can also do this by searching for your business account in the search box, and turning device updates on there). You also have to turn on device updates on the main Twitter page, and go to settings/devices and turn device updates on there. Do another tweet from you business account and make sure you get an SMS message.

Obviously if you can't make this work, you won't be able to get your cart to tweet, so please don't do anything further until this works.

Once you have verified that this works, modify class.msg_owner.php, and replace the call to zen_mail() with the following:

      // Set username and password
      $username = 'your-twitter-account-email';
      $password = 'your-twitter-password';
      // The twitter API address
      $url = 'http://twitter.com/statuses/update.xml';
      $curl_handle = curl_init();
      curl_setopt($curl_handle, CURLOPT_URL, "$url");
      curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
      curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($curl_handle, CURLOPT_POST, 1);
      curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$email_text");
      curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
      $buffer = curl_exec($curl_handle);

Obviously to make this work, you must do the following:
  • Set up a business account with Twitter and fully configure it
  • Fill in $username and $password with your actual Twitter credentials
  • Execute this code on a host with cURL. If your host doesn't have cURL, get one that does.
Once you're done this, run through a test sale on your cart and make sure you get an SMS message from Twitter.

Please remember that Twitter is a free service, so it does not offer ultra-high reliability. If you need bulletproof SMS, you will have to buy it. Google "SMS Gateways" for a list of providers.

Installation Instructions:

  1. Back up everything! Try this in a test environment prior to installing it on a live shop.
  2. Test your mobile's ability to receive SMS by sending your mobile a brief text-only email from your regular email client (Gmail, Outlook, etc.). If you can't get that to work, you won't be able to use this mod.
  3. Copy the contents of the folder you have unzipped to the root directory of your shop. There are two new files in this mod.
  4. Edit the file includes/classes/observers/class.msg_owner.php

    and enter your mobile email address at the top where it says
       var $owner_phone = "2125551212@vtext.com";
  5. If you wish to be able to turn SMS messaging on and off from your admin panel, run the "config.sql" script against your database. The setting, which is called "Send SMS Message when a sale is made," is in Admin > Configuration > E-Mail Options.
  6. Donate! Show your appreciation by supporting my efforts.
  7. You're done! Put through an order to be sure it works.

Major Versions

  • 1.1a 12/07/2010 - Documentation updates
  • 1.1 02/01/2007 - Adding switchability from the admin panel.
  • 1.0 01/01/2007 - First Release


Q: What's my mobile's email address?
A: If you're in the US, here are the addresses for the big guys:
  • AT&T: AreaCode+Mobile@mobile.att.net
  • Verizon: AreaCode+Mobile@vtext.com
  • Nextel: AreaCode+Mobile@page.nextel.com
  • T-Mobile: AreaCode+Mobile@tmomail.com
  • Sprint: AreaCode+Mobile@messaging.sprintpcs.com
  • Cingular: 1+AreaCode+Mobile@mobile.mycingular.com

Q: I'm not on that list! What's my mobile's email address?
A: Here are some possible solutions:
Q: I live outside North America, and my provider doesn't offer a free email to SMS gateway - what can I do?
A: Traditionally, European providers charge on SMS transmission (not SMS receipt) so they often do not offer free gateways the way US providers do. If you cannot find a free gateway, you will have to open an account with an account with a commercial provider, purchase credits, get a copy of their API, and add logic to this contribution to interface with their system. You may need to use HTTP POST, or they may provide you with an email address.

Q: SMS on Sale doesn't seem to work with PayPal IPN in Zen Cart 1.3.9 - why?
A: To get SMS on Sale to work with PayPal IPN, you have to do a little more work.
Edit the file ipn_main_handler.php at the top level of your store, find the line
   $order->send_order_email($insert_id, 2);
it's line 354 in 1.3.9h (line 253 in 1.3.8, line 219 in 1.3.7). Change this to:
   $order->send_order_email($insert_id, 2);
   require(DIR_WS_CLASSES . 'observers/class.msg_owner.php');
   $mo = new msg_owner();
Note that this issue has been fixed in Zen Cart 1.5.0 and higher.

Q: In 1.3.8 and above, SMS on Sale adds a CAN-SPAM message to the text; how do I delete this?
A: This logic was added to a core file in 1.3.8. To modify it, back up the file includes/functions/functions_email.php and modify it. Go to function zen_mail in this file, and search down until you see
      if ($module != 'xml_record') {
   if (!strstr($email_text, sprintf(EMAIL_DISCLAIMER, STORE_OWNER_EMAIL_ADDRESS)) && $to_email_address != STORE_OWNER_EMAIL_ADDRESS && !defined('EMAIL_DISCLAIMER_NEW_CUSTOMER')) $email_text .= "\n" . sprintf(EMAIL_DISCLAIMER, STORE_OWNER_EMAIL_ADDRESS);
   if (!strstr($email_text, EMAIL_SPAM_DISCLAIMER) && $to_email_address != STORE_OWNER_EMAIL_ADDRESS) $email_text .= "\n" . EMAIL_SPAM_DISCLAIMER;

this starts on line 109 in 1.3.9h (line 101 in 1.3.8a). Change the first line of this block to:

      if ( ($module != 'xml_record') && ($module != 'msg_owner') ) {

Q: I am using email archiving. How do I stop archiving the SMS on sale messages?
A: Back up the file includes/functions/functions_email.php and modify it. Go to the bottom of the function zen_mail in this file, and you will see
      // Archive this message to storage log
// don't archive pwd-resets and CC numbers
if (EMAIL_ARCHIVE == 'true' && $module != 'password_forgotten_admin' && $module != 'cc_middle_digs' && $module != 'no_archive') {
   zen_mail_archive_write($to_name, $to_email_address, $from_email_name, $from_email_address, $email_subject, $email_html, $text, $module, $ErrorInfo );
} // endif archiving

This is on line 308 of 1.3.9h (line 295 of 1.3.8). Change the first line of this block to:

      if (EMAIL_ARCHIVE == 'true'  && $module != 'password_forgotten_admin' && $module != 'cc_middle_digs' && $module != 'no_archive' && $module != 'msg_owner') {

Q: Why can't I just add my mobile email address in the Send Copy of Order Confirmation Emails To field in Admin/Email Options?
A: SMS stands for "short message service." The stock emails the cart sends are not short! Most mobile text messages have a length limit, and the regular order confirmation email is much too long; it would be truncated before any useful information was received.

Q: Why doesn't your mod work?
A: Actually it does - it just doesn't work in your setup, and you will have to debug it. Try these suggestions:
  • Double check your phone number in class.msg_owner.php
  • Try sending mail from your regular email client to your mobile and be sure you can get that to work.
  • If the host where you run Zen Cart offers webmail, try sending a message from that email account to your mobile.
  • Try adding your mobile to Admin/Email/Send Copy of Order Confirmation Emails To. The email will be clipped but it will help you verify whether you can receive messages from your server.
  • Check the Zen Cart Email Help Tutorial.
  • Beyond this, your mobile provider may discard these messages as spam. Call your service provider and see if they can see what's going on.