Colin McCann Dot Com

Automated Email-to-SMS gateway PHP script

Posted on May 7, 2009 at 9:06 am

I’ll cut right to the awesome. This script runs every minute, checks an IMAP mailbox (that happens to be my work email), and detects if any new messages have been received. If so, all HTML and special characters are stripped (leaving plain ASCII text) from the message body, and truncated to 150 characters. Next, the script sends me a text message through Verizon’s email gateway “from” the original sender’s email address.

This is cool for a number of reasons. One, I don’t have to run an IMAP application on my phone; updates are pushed to me from an external source. Two, I don’t need a data plan to use it (although I may need to increase the number of texts I can receive without additional charges). Three, I can reply directly from my phone (although the message is received from a different address, depending on your carrier). Four, it’s got an accuracy of around one minute, and so far that has been more than adequate.

You need to create a web-writable file (chmod 755) called timestamp.txt in the same directory. I’ll include the cron script at the end of this post.

Cron script:

Code
11 comments for this entry:
  1. John
    Hi Colin, Thanks for your code, looks awesome. I have an API from http://www.smsgol.com/en/developers which is sending SMS to my customers and to me from my osCommerce store, but now I wanted to change it to send SMS via email address, your code gave me a BIG picture of how to do it and now I'm giving a try. Regards and thanks a lot, John
  2. admin
    John -- best of luck. I'm glad you found this post helpful.
  3. Stephen
    This is awesome. It helped me fix an unrelated problem. Very well-written code as well. I like the idea. :)
  4. Clone Scripts
    Great post, excelent writing. ps. Where are rss feeds? I would love to sindicate news from this blog.
  5. Neelkamal
    I am trying to execute a shell/php script that will be integrated with the postfix server config file which will be executed when a new mail arrives and the shell/php script would check a config file for the domain(s) that are configured to send mail2sms alert and if found would send sms by processing the mail body to the sms gateway api which could be an generic http link for sending sms. Regards.
  6. seo services delhi
    Hello! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no back up. Do you have any solutions to prevent hackers?
  7. admin
    Actually, yes, I have a number of passive intrusion detection scripts running on most of my websites designed specifically to prevent this sort of thing (and alert me in the process). I've been hacked before, and it's no fun, but I learned a LOT from it, and I don't expect it to happen again anytime soon due to the measures I've taken. Expect a post detailing some of the methods I use within the next month or two.
  8. R. Wilkins
    Colin, nice post. You have a lot of useful advice. Where do the scripts get saved? Can I use them in a shared environment? Thanks, Bob
  9. admin
    Bob -- the scripts can be saved anywhere that you can reference in your crontab. I was using this script in a shared environment (Dreamhost) for a couple years, up until I got a phone with a data plan that made this obsolete for me.
  10. farooq
    Hi How can I connect to my hosting server to access my email through this script. what should I place in {imap.gmail.com:993/imap/ssl}INBOX I am trying to connect to imap through port 110 which I have verified with my hosting company.
  11. Rashad
    thanks, it works very well

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...